Subject: Re: a shell idea?
To: VaX#n8 <vax@ccwf.cc.utexas.edu>
From: Greg A. Woods <woods@kuma.web.net>
List: current-users
Date: 10/12/1995 12:02:45
[ On Sun, October 8, 1995 at 23:56:02 (-0500), vax@ccwf.cc.utexas.edu wrote: ]
> Subject: a shell idea?
>
> I was wondering about this shell idea I had.
> The basic notion came from the fact that path manipulation is difficult.
> For example, it's difficult (but can be done) to do a command like:
> ``Add this directory iff it's not already in the path''
> or variations like:
> ``Add this directory iff it [and every parent directory] are protected
> from writing by anyone but root or bin''
> This would be especially cool if it was one builtin command, IMHO.
I think I promised to send you my .profile, etc., which have a way to do
this in existing Bourne and Korn Shell compatible environments,
including 4.xBSD's ash. Remind me again if you'd like a copy of my huge
but fairly portable .profile and associated files.
Here's the guts of the simplest implementation:
dirappend ()
{
if [ $# -le 1 ] ; then
echo "Usage: dirappend variable directory [...]" >&2
exit 2
fi
varname=$1
shift
eval varvalue='$'$varname
while [ $# -gt 0 ] ; do
if [ -d "$1" -a `expr ":$varvalue:" : ".*:$1:.*"` -eq 0 ] ; then
eval $varname='$'"$varname"'":$1"'
fi
shift
done
unset varname varvalue
}
dirprepend ()
{
if [ $# -le 1 ] ; then
echo "Usage: dirprepend variable directory [...]" >&2
exit 2
fi
varname=$1
shift
eval varvalue='$'$varname
while [ $# -gt 0 ] ; do
if [ -d "$1" -a `expr ":$varvalue:" : ".*:$1:.*"` -eq 0 ] ; then
eval $varname='"$1:"$'"$varname"
fi
shift
done
unset varname varvalue
}
--
Greg A. Woods
+1 416 443-1734 VE3TCP robohack!woods
Planix, Inc. <woods@planix.com>; Secrets Of The Weird <woods@weird.com>