Forcing /bin/sh in a script under V/386 3.2 Korn shell

Andrew Dingwall andrew at root.co.uk
Tue Aug 1 03:15:57 AEST 1989


In article <799 at jonlab.UUCP> jon at jonlab.UUCP (Jon H. LaBadie) writes:

 	... Much deleted ...

>Combining these comments and using the conditional operator rather than
>an if statement; plus quoting $0 on general principles, we have:
>
>  [ "${RANDOM}" = "${RANDOM}" ] || exec /bin/sh -c "${0}" ${@:+"${@}"}
>

Careful, when you use sh -c "string ...", arguments after the string are
assigned to positional parameters starting with $0 - not $1 as one might expect.

for example, try this:

	$ /bin/sh -c 'echo $@' a b c d
	b c d
	$ /bin/sh -c 'echo $0 $@' a b c d
	a b c d

(this happens on System V (at least)).



More information about the Comp.unix.questions mailing list