|
|
Prevent .cshrc customizations from impacting scripts
Using the backslash in front of a command will override the alias for that command. Works pretty much with all the major Unix shells.
So for example, if you have rm aliased to
you can override it at the command line by typing
Prevent .cshrc customizations from impacting scripts
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.
Similar Korn and Bourne tricks of the trade
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.)
The other change I'd recommend in Korn (POSIX) and Bourne scripts is to use (or ; 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 , to exit automatically on a failed command that doesn't have error checking associated with it. Scripts that ignore errors are evil.
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.10 seconds |
|