by jdkanani on 12/15/15, 8:17 AM with 52 comments
by catern on 12/15/15, 10:10 AM
Three real defensive bash programming tips are:
- Quote all uses of variables
- set -o nounset
- set -o errexit
And many others can be found in and around http://mywiki.wooledge.org/BashFAQ
by reacweb on 12/15/15, 9:31 AM
I agree that the function call introduces a better name. The problem is that this name is specific to the author of the script. It replaces a reusable tricky knowledge of the language by a simple knowledge of the author usages.
If we take into account the increased verbosity, increased typing, increased number of lines, there is a clear loss in using these functions.
For me, adding a comment would be far enough and far less annoying.
by c0l0 on 12/15/15, 10:22 AM
main() {
local files=$(ls /tmp | grep pid | grep -v daemon)
}
by Gnouc on 12/15/15, 9:03 AM
by jakub_g on 12/15/15, 10:01 AM
I used to write my various glue-things-together scripts in bash, but this quickly becomes a nightmare as the script grows, due to bash's corner cases, syntax, portability issues etc.
Recently I wrote my massive glue-things-together script with nodejs (since I already use node for many things) and it's much more maintainable and I couldn't be more happy. Node 0.12 has execSync which was the missing piece for making node the proper shell scripting platform.
If you are interested, you may want to check shelljs [1] and my snippets for robust `exec()` and `cd()` in node.
[1] https://github.com/shelljs/shelljs [2] https://gist.github.com/jakub-g/a128174fc135eb773631
by voltagex_ on 12/15/15, 9:18 AM
by makecheck on 12/15/15, 2:56 PM
Any sufficiently-complex shell script can usually be written clearly as a Python or Perl program for instance, without having to worry about how the code might be misinterpreted.
Yes, I write shell scripts sometimes. I just make sure they're doing something pretty straightforward.
by ehartsuyker on 12/15/15, 9:00 AM
by emmelaich on 12/15/15, 11:35 AM
ls $dir \
| grep something
is the same as ls $dir |
grep something
by falsedan on 12/15/15, 9:06 AM
I've been enjoying BATS [0] for my bash testing.
by ceruleus on 12/15/15, 12:24 PM
by labianchin on 12/15/15, 4:33 PM
by chmielewski on 12/15/15, 1:54 PM
by lisivka on 12/15/15, 9:46 AM
by matobago on 12/15/15, 9:18 AM
by dang on 12/15/15, 9:24 AM
by peteridah on 12/15/15, 10:19 AM
by moviuro on 12/15/15, 12:21 PM
by IshKebab on 12/15/15, 12:28 PM
by emmelaich on 12/15/15, 11:36 AM
set -u
set -e
with trap 'echo $0 internal error at $LINENO' ERR
by fergie on 12/15/15, 9:25 AM
by unixhero on 12/15/15, 9:29 AM
by Grexception on 12/15/15, 2:27 PM