Comment some UNIX habits (Score 1) 360
Clearly this post is too old for anyone to care about, so I'll do it just to mark the article.
While I agree with
- Avoid the use of || and && on the command line. They are squirrely between different systems, and as some other reader pointed out, you should just run a command and see what happens. You're not in a script. Also, I am afraid of A || B && C - what happens? A and C, B and C, or just A? Operator precedence matters.
- Be careful about tars. I spent 2 years managing open source, and found that while most authors correctly name a root of the extraction
./my-package-1.2.3, some just put all their files in the current directory. You need to "jail" your tars carefully. - Why not do "grep 'Dec '" for that grep example, instead of invoking awk? Point is, look at your data, then decide the simplest way to handle it.
- Piping cats is a loopy comment. Nobody cares. Also, the wc -l saving 0.84 seconds is loopy, as well.
- If you find yourself using many backslashes to continue a line, then you should be writing a script. Actually, the best thing you can do is open a notepad-like editor and build your command line in that, then paste it to your shell window.
Now, for my tips:
- Never depend on a variable being set when doing a remove. That is, NEVER do "rm -rf $SOMEPATH/*" because if SOMEPATH is not set, guess what gets removed? Uh huh.
- Always back up your MBR before making serious changes to your filesystem. Do this using "dd if=/dev/hda of=mbr.bin bs=1 count=512" and ideally put it on a USB stick. It's free, takes little time, and you can always restore your MBR from a bootable Linux distro such as SysRescueCD (my fav) if you really hose things up.
- Quit using CSH, like some other poster said. Use bash. It's everywhere.
- Pipe error output into a file, not just stdout. Somecommand >output.txt 2>&1 will write everything including errors into output.txt. If you ignore the 2>&1 (which says, duplicate stdout and route stderr into it), you only get the normal output.
Hope this helps.