Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

funny test

Status
Not open for further replies.

hok1man

Technical User
Feb 16, 2008
102
can someone tell me what's the meaning of this :

Code:
# *** Am I a C-shell or K-shell type; and is 'Load' already defined? If so, exit.

test "$?path" = 1 \
        && eval 'set SHELL=$shell ; \\
                 set _loadAlias="`alias Load`" && \\
                 if ( "$_loadAlias:q" != "" ) exit 0 ; unset _loadAlias' \
        || [ "$RANDOM" != "$RANDOM" -a \
                "`type Load 2>&1`" != "Load not found" ] && return      # ksh

They checking the shell.. but I dont quite understand how the codes work..
can someone explain?
 
hok1man

The
Code:
test "$?path" = 1
is true under csh but false under ksh.
So, if csh then do the
Code:
eval 'set SHELL=$shell ; \\
                 set _loadAlias="`alias Load`" && \\
                 if ( "$_loadAlias:q" != "" ) exit 0 ; unset _loadAlias'
bit
The
Code:
"$RANDOM" != "$RANDOM"
is only true under ksh so, if its a ksh the it tries the
Code:
`type Load 2>&1`" != "Load not found"
test and returns if that is true.

The true explanation is some awkward so-and-so has tried to be far too clever and left the poor sods who follow on behind with unsupportable code. This should be a lesson to us all - DON'T BE CLEVER!!!

On the internet no one knows you're a dog

Columb Healy
 
Thanks columb,

But looks like that code not completely handling human error, the true is ksh can be true in bash and sh as well.

But the programmer just allow in ksh only...
he didn't give us the warning if we running in bash or sh, just the program don't work..

they should do more about it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top