Menu

#2 coerce bash shell execution

open
nobody
None
5
2005-03-23
2005-03-23
No

Similar to when it was Ksh vs the Bourne shell ( just
plain sh)
Dave Korn showed off his

run-the-ksh-if-you're-not shell hack, placed on the
first executable
line in the script:

one=1; [ one -eq 0 ] && exec ksh $0 $*

it works because

a. the Bourne shell knows how to gracefully
not require a variable to have a dollar sign, _and_
return a zero, and
b. the ksh allows shell variables to be tested
without requiring the dollar sign.

e.g. in "sh" one = 0
and in "ksh" one = 1

therefore, if you are NOT in the ksh, exec it (it had
better
be in your PATH) with the name of the command - $0,
and all the arguments - $* !!
"obviously", if you are running the ksh, the test
fails, and
execution proceeds.

Today, i suspect there is a sh <-> ksh <-> bash sequence
to coerce bash! ==> To Do List

Discussion


Log in to post a comment.

MongoDB Logo MongoDB