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


Click here to return to the 'Prevent .cshrc customizations from impacting scripts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Prevent .cshrc customizations from impacting scripts
Authored by: LC on Aug 01, '05 10:48:20PM
Or else (for binary executables) ... /bin/rm; but for shell built-ins, the backslash is good. Also, can first unalias any commands that we know we'll use in the script (for good measure) ... and, the command path can be another BIG gotcha; (especially when your script will be run by another user!)

It (csh, tcsh) is just not such a great shell for serious script programming. Certainly software vendors should never ship csh scripts as production material. Boot-time (startup/shutdown etc.) scripts are sh, ksh, bash for good reason! Larry.

[ Reply to This | # ]

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 | # ]