Click to See Complete Forum and Search --> : Me and Nix


jumper
11-11-2005, 01:41 PM
z999999@ubns99> echo `$ENV`
ksh: /export/home/z999999/.kshrc: cannot execute

z999999@ubns99> echo $ENV
/export/home/z999999/.kshrc




I've just taken this line from a library function and it's telling me it cannot execute

z999999@ubns99> echo `$ENV | $GREP "${i}=" | $AWK -F= '{print $2}'`
ksh: /export/home/z999999/.kshrc: cannot execute
ksh: -F=: not found
ksh: =: not found

and here is the old chestnut ;)

but it appears to be working in the function

I want to check the parameters of a function with this inside it [which will be environment variables] for values


can you tell my why please ?


tia

jumper
11-21-2005, 07:49 AM
anyone know a Unix forum I can post this on please ?

NogDog
11-21-2005, 08:10 AM
Well, $ENV, $GREP, and $AWK would appear to be variable names, oddly enough appearing to be the same as the functions the author wants to use there (changed to upper case). Maybe he sets their values somewhere else?

Anyway, I expect you might have some success with:

echo `env | grep "${i}=" | awk -F= '{print $2}'`

In fact, if running from the command line, you can get rid of the echo and the back-ticks (``).

However, I don't know what the ${i} variable is supposed to be, presumably it gets set somewhere in the script before this line gets executed.

Whatever it's value is, grep is looking for that value followed by an equals sign in the output from the env command (which displays info about your shell environment), then the awk command is formattig the output -- if my memory is not too awful it's just printing the 2nd field of each line that grep matches.

Stephen Philbin
11-21-2005, 08:22 AM
Thing that sticks out most for me is

ksh: /export/home/z999999/.kshrc


and the not found. Well on Linux, not sure about other nix gubbins, I'm pretty certain it would never be found. kshrc is prefixed with a . which means it's a hidden directory.

jumper
11-22-2005, 06:59 AM
thanks for that chaps, I'll give it another try


NogDog: perhaps I should have shown the whole function I'm trying to create


check_key_env() {
for i in $1 ; do
#print $1
j=`$ENV | $GREP "${i}=" | $AWK -F= '{print $2}'`
if [ "${j}x" = "x" ] ; then
echo "$(date) Environment Variable $i is not set"
exit 1
fi
#print `$ENV | $GREP "${i}=" | $AWK -F= '{print $2}'`
done
}