[ Off-topic: ]
johnpowell, it’s not rm
that scares me… it’s the shell’s substitution logic.
—
My first PC ran DOS 1.0. I picked up DOS syntax pretty quickly and learned that if I wanted to change the extension on a bunch of files, it’s easily done like this:
rename *.txt *.boo
—change all filenames ending with .txt to end with .boo instead.
Indeed, in DOS, to delete all files in a directory, you simply type delete *. *
. Easy. (forgive the spacing, adjust for textile)
—
Now, take this DOS-based knowledge to your first UNIX system. You want to rename a bunch of files again to change the extension. If you try DOS-style syntax…
mv *.txt *.boo
…then you’re putting yourself in a bag of hurt. Because the UNIX shell pre-processes those asterisks before processing the mv
command. The actual execution is:
mv 1.txt 2.txt 3.txt *.boo
Yah, take it from me, that’s a sure-fire way to lose one’s C++ programming assignment less than 15 minutes before it’s due.
Couple UNIX’s default behavior not to ask “Are you sure?” before doing something damaging (unless you provide the -i
switch) and yah, anything bad can happen pretty easy.
—
Lessons I’ve learned the hard way:
– try echo
‘ing a potentially dangerous command first: echo rm -f /path/*
– never run as root by default
– never run anything with sudo unless you’ve tested it
– never trust your interpretation of the shell substitution
– never expect cron to run something exactly the same as your interactive shell
…and I could go on and on.
Still, UNIX shell beats the crappity smack outta lame-ass DOS syntax. And don’t even get me started on Windows Powershell.