Stewart Stremler wrote:
> begin  quoting John H. Robinson, IV as of Thu, Mar 03, 2005 at 12:34:58AM 
> -0800:
> [snip]
> > # TODO: if there is no env var supplied, default to using $PATH
> > #i cannot seem to do that in pure sh. if i look in the output of env,
> > #yes. if i use bash or zsh, yes. pure sh? not that i have found, yet
> 
> How about a simple, short example that demonstrates exactly the
> behavior that causes the problem?

read first option
if option is an env. var, 
  then use it
else
  use PATH as a default

in bash:

var=$1
VAR=${!var-ThisVarNotSet}
if [ .$VAR = .ThisVarNotSet ];
  var=PATH
  VAR=${!var}
fi

in zsh:

var=$1
VAR=${(P)var-ThisVarNotSet}
if [ .$VAR = .ThisVarNotSet ];
  var=PATH
  VAR=${(P)var}
fi

In sh, I could use env and grep. I'd prefer to avoid that.

var=$1
if [ ! env | grep \^$var= >/dev/null 2>&1 ];
  var=PATH
fi
VAR=`eval echo \\$$var`

Mostly untested.

-john
-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to