3 ms·
Some off the top of my head. * On Linux file and directory names can be anything except NUL. Because of how much software already assumes they’re UTF-8 you can
by Spivak 6y ago
Some off the top of my head.
* On Linux file and directory names can be anything except NUL. Because of how much software already assumes they’re UTF-8 you can probably safely assume it too and not run into much trouble. But since bash basically just does some text substitutions and then calls eval you have to be defensive.
* Know how bash parses front and back. Almost all the pitfalls are unexpected consequences of the parser not behaving how you expect.
https://web.archive.org/web/20200124085320/http://mywiki.wooledge.org/BashParser https://web.archive.org/web/20200124085320/http://mywiki.woo...
- mfontani 6y agoIIRC directory (and file) names can contain anything but slash and null, not just null.
- bewuethr 6y agoPretty much this, and as a subset of it: quoting, word splitting, the IFS variable and friends. Reading the BashGuide [1] cover to cover is an excellent base, I find. [1]: https://mywiki.wooledge.org/BashGuide https://mywiki.wooledge.org/BashGuide
- doctoboggan 6y agoDo you know if the `--` trick mentioned in the article to stop option scanning works with all bash programs? I thought parsing was up to the program itself. Is it just a widely used convention?
- scbrg 6y agoYou are correct, option parsing is up to each program. The double dash is just a convention.
- joombaga 6y agoYes, it's just a widely used convention, and a POSIX guideline. 12.2 Utility Syntax Guideline #10 https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1...
- JdeBP 6y agoTalking of mental models: These are not "bash programs". Most of the ones where you need this mechanism have nothing to do with the Bourne Again shell, and are just generally-usable utility programs, usable even by things which aren't shells at all. They are, generally, programs that happen to use library mechanisms such as (but not limited to) getopt() or the popt library to parse their arguments.