Had a bunch of python scripts in a directory.

They all needed some munging. It was too complicated for my sed
skills, so I wrote a python script to munge the python scripts.

Here's how I ran it:

for f in UC*.py; do cp $f $f.orig; ./munge $f.orig > $f; echo $f; done

Only problem was, the script was called munge.py, not munge, so I got
a whole bunch of:

bash: ./munge: No such file or directory

Oops. up-arrow twice to previous command and change to ./munge.py:

for f in UC*.py; do cp $f $f.orig; ./munge.py $f.orig > $f; echo $f; done

Just about to hit return, when I decided to quickly check the directory listing.

Yep. Every file matching UC*.py was of zero length. If I had run the
correct version, It would have copied the zero-length version over the
$f.orig version, and all would have been lost! Except, of course, the
files are in a version control system, so all would not have been
lost.

Moral of the story: The shell interprets shell redirects, not the
program. Even if the program fails, the redirect (such as > foo) will
create a zero-length foo, clobbering any existing foo. I think you can
turn off this useful feature with a noclobber option in the shell.

Second Moral: Backups or version control systems are a Good Idea.

Cheers,
Carl.

Reply via email to