How to screw up while shell scripting

---written maybe 2 years ago and never posted --- posting it now ---

Okay, in my past 3 months or so of doing shell scripting, I've screwed up more than in my whole career of 2.5 years. So I know quite a few things about screwing up.

1. Use rm -rf
It's beautiful. It's fast. You can become terminator in a single Enter key. But of course even Terminators feel guilty after a while and hunt for undo rm -rf in Stack Overflow.

2. Use global environment variables
Wow. It's so cool that you can export just about anything and use it wherever you want. Of course, anybody around can modify your variable. Why only you have all the fun ?

3. Quotes in variables ? Never bother
Just sing along:
MESSAGE=I have a dream..a song to sing..

Why bother doing:

MESSAGE="I have a dream..a song to sing.."

Quotes take effort to type

4. And then do something like rm -rf $myfilename*.processed
So lovely that if $myfilename is undefined, it'll clean up everything - super awesome if you're housekeeping your file from a backup location

5. mailx with attachments

echo "Things went fine. Results have been copied to X location. Error records are in the attached file" mailx -a $error_file -s "Report: Successful" youremail@company.com

But it so happened that there were no errors and $error_file does not exist

When there are no errors, why do you even want to know if it was successful, no ?



Comments