Saturday, September 29, 2007

Bash's noclobber

If there is something I don't miss is a chance of thumbing through a new book. It always seems that I never have enough money to buy them all, so the resort to the next best option. To seek out engineering students who buy books in the feverish days before the examinations only to banish them to the dark and dusty corners. Needless to say these are technical books explaining basics of languages or Unix shell environment, a particular favorite of mine.
Perhaps it is my insatiable curiosity that drives me to read all books even the 'for Dummies' books which are looked down with disdain by other geeks, I find them amusing and entertaining.

Lately I have started noticing that some information was missing here and there. For instance, the setting of no clobber of existing files is nowhere to be seen in shell books these days , I guess the authors of these technical books consider it unimportant and almost trivial.

The no clobber setting however is life saving sometimes, it prevents accidental overwriting of existing files while using IO redirection on bash shell or badly written shell scripts. It is better to set it with set -C than losing a very important file .

$ set -C # Enable it $ ls > foo bash: foo: cannot overwrite existing file $ set +C # Disable noclobber $ ls > foo # exiting file overwritten!!!

Just include a line with set -C option somewhere in .profile or .bashrc file inside your home directory.

No comments:

Post a Comment

You can leave a comment here using your Google account, OpenID or as an anonymous user.

Popular Posts