4 ms·
The first rule of defensive bash programming should be: quote everything. Incredibly, the article doesn't mention quoting at all, doesn't even use it silently i
by mooism2 12y ago
The first rule of defensive bash programming should be: quote everything. Incredibly, the article doesn't mention quoting at all, doesn't even use it silently in examples.
- twic 12y agoHe also doesn't set -eu or -o pipefail.
- chrismonsanto 12y agoI always recommend people use zsh for scripting instead of bash--it gets word splitting right. Most of my sysadminny scripts start with #!/bin/zsh these days. It would be really nice if Linux distros came with zsh installed automatically! For some reason the shell quoting behavior never seems to get brought up when comparing zsh and bash. It is, IMO, the most important distinction between the two shells.
- Florin_Andrei 12y agoAs someone who's never used zsh - you don't need to quote stuff in zsh?
- dozzie 12y agoIt depends on options set. There is one that causes word splitting only to happen when explicitly asked for.
- chrismonsanto 12y agoBy default, no. Word splitting only happens when you request it: ${=words}. It reminds me of ,@list in Lisp, which is a warm and fuzzy feeling.
- kondor6c 12y agoThat's the tricky thing about 'sysadminny' scripts is that they generally need to be written for the least common denominator, which usually ends up being a very old version of $(software). I frequently have to use Python 2.4 to reach many of the RHEL-ish 5 machines in our environment.
- moe 12y agoActually the first rule of bash programming should be: Don't use bash. If your script is longer than 10 lines then you should probably write it in a less error prone language.