4 ms·
Shell [Scripting] Style Guide
- reayn 5y agoThis pairs extremely well with dylan's Pure Bash/sh Bible [1], both, combined with admittedly way too many hours browsing random people's dotfiles can exponentially increase your skills with shells scripting. Some tips of my own: Adding `2>/dev/null` or `>/dev/null 2>&1`after most commands with expected or just plain useless output can make writing headless scripts very easy, it also comes in very handy when trying to shut up some basic utilities. A handy function: execute() { pkill -x "$1" { sleep 0.1 "$@" & } } >/dev/null 2>&1 `set --` before running a command can be used to remove all excess whitespace (making parsing dead easy). And last but not least always using printf instead of echo makes your scripts 1000x cooler :) 0. https://github.com/dylanaraps/pure-sh-bible https://github.com/dylanaraps/pure-sh-bible 1. https://github.com/dylanaraps/pure-bash-bible https://github.com/dylanaraps/pure-bash-bible
- wodenokoto 5y agoWhy is printf better than echo?
- jicea 5y agoFollowing a style guideline is really important in scripts. But, having your scripts checked by ShellCheck [1] is really mandatory. Can’t imagine to write any script without it. [1] https://www.shellcheck.net/ https://www.shellcheck.net/
- hall0ween 5y agoWhat’s the step up in terms of “structured languages” from bash. My shell scripts are getting longer as I become more competent. The one I am aware of is perl, any others?