Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Similar Korn and Bourne tricks of the trade' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Similar Korn and Bourne tricks of the trade
Authored by: greed on Aug 02, '05 02:17:58PM
Ugh, hard-coding pathnames in commands is a different kind of evil; consider an 'rm' upgraded to handle meta-info on some weird filesystem that isn't supported by the standard /bin or /usr/bin commands. There's no reliable way to presume the 'rm' you want is in /bin or /usr/bin or /usr/xpg4/bin or whatever, if cross-UNIX portability matters.

I don't use C Shell, but the Korn (POSIX) shell has a "command" keyword, so you can definately get the actual command by regular path search, no alias, no function. (I think Bourne shells have it too.)

command rm ...

The other change I'd recommend in Korn (POSIX) and Bourne scripts is to use

#!/bin/ksh -p
(or
#!/bin/sh -p
; that turns on "privileged" mode, intended for set-user-ID scripts, but it also prvents the shell from loading the user's ~/.*rc files, so no surprising functions or aliases.

And don't forget

#!/bin/ksh -e
, to exit automatically on a failed command that doesn't have error checking associated with it. Scripts that ignore errors are evil.

[ Reply to This | # ]