4 ms·
Ask HN: A Bash guide for Posix shell programmers?
I've been programming POSIX shell for a while and know pretty much all of it (the spec isn't that long: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html). I mostly stayed away from Bash because of the "it runs everywhere" promise of POSIX but recently I've realized that most of the scripts I write will probably always run on machines with Bash installed anyways. I'm looking for a guide that explains Bash features specifically and doesn't go over the whole shell programming basics again. I know some features here and there, e.g. I know that Bash has arrays and a syntax to redirect the contents of a variable to a file, but I'm looking for a comprehensive list of what's possible. Are there any resources you can recommend?
- haltist 3y agoLearn Bash the Hard Way by Ian Miell
- tschumacher 3y agoIt turns out the Bash manual groups the Bash specific features into its own chapter [1] and it's a short read and also there are not nearly as many Bash specific features as I thought. [1] https://www.gnu.org/software/bash/manual/bash.html#Bash-Features https://www.gnu.org/software/bash/manual/bash.html#Bash-Feat...
- 1vuio0pswjnm7 3y agoBash is slower. That's why a major Linux distribution would switch to NetBSD Almquist sh. On a Linux distribution, generally, bash is always found in the userland. But for scripting (non-interactive use), it's big and slow.
- znpy 3y agoIf i'm writing shell scripts i'm not caring about speed anyway. The "slowness" of bash versus some other shell is likely irrelevant, most of the time will be spent forking and executing other binaries anyway.
- 1vuio0pswjnm7 3y agoWhat if the people administering Debian project are writing shell scripts. Why do they use Dash instead of Bash. Who cares, right. The speed difference is substantial. It's noticeable. This is indisputable. I would never use Bash for scripting when faster alternatives are available. But who cares, right. The fact that Bash is big and slow is independent of what any HN commenter chooses to do or not do. It is a fact indepedent of any decision a particular script author chooses to make.
- NukedOne 3y agoYou might find this useful: https://mywiki.wooledge.org/BashGuide https://mywiki.wooledge.org/BashGuide
- dharmab 3y agoThe three most important resources I've used: - https://tldp.org/LDP/abs/html/ https://tldp.org/LDP/abs/html/ - https://mywiki.wooledge.org/BashGuide https://mywiki.wooledge.org/BashGuide - https://www.shellcheck.net/ https://www.shellcheck.net/ (can tell you if there's a Bash-specific replacement for a POSIX mechanic) I'll be reading this book over the break: https://fabiensanglard.net/bash/ https://fabiensanglard.net/bash/
- atmosx 3y agoOr buy a book that covers nearly everything these is to know: https://www.amazon.co.uk/dp/1119700914?linkCode=gs2&tag=uuid07-21 https://www.amazon.co.uk/dp/1119700914?linkCode=gs2&tag=uuid...
- x1sec 3y agoRecently having stumbled across the VSCode shellcheck plugin[1] - it's been particularly educational as it provides not only corrections but improvement tips. For example the common practice of: if [ $? -ne 0 ]; then Will get flagged and an improvement will be suggested with an explanation on why [2] [1] https://marketplace.visualstudio.com/items?itemName=timonwong.shellcheck https://marketplace.visualstudio.com/items?itemName=timonwon... [2] https://www.shellcheck.net/wiki/SC2181 https://www.shellcheck.net/wiki/SC2181
- runjake 3y agoThis may not explicitly meet your requirements, but I always find this site handy for quick reference: https://learnxinyminutes.com/docs/bash/ https://learnxinyminutes.com/docs/bash/ It helpfully also links to the Bash manual: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash....