9 ms·
Advanced Shell Scripting with Bash (2006) [pdf]
- xrayarx 2y ago60 slides from a bash workshop?
- pottmi 2y agoIt is not how to code in bash, it is how to avoid the bash pitfalls.
- kedislav 2y agoWebsite seems to be down or dead, consider using the archived link [1]. Also, since these are slides, it'd sure be nice to have the presentation on video form since a lot of context is missing from the slides. It does not seem to be available (well, it is from October 2006). From the archived site's abstract [2]: >"bash (and scripting languages in general) act as the glue that hold other system components together. This presentation will focus on the under utilized features of bash that are critical to building production quality scripts. Demos will show you how and why to turn these features on." EDIT: seems the website being down is a me issue (?), but still, having the archives doesn't hurt. --- [1]: https://web.archive.org/web/20241212102046/https://uniforumchicago.org/slides/bash1.pdf https://web.archive.org/web/20241212102046/https://uniforumc... [2]: https://web.archive.org/web/20240719092417/http://uniforumchicago.org/meetings/bashscripting.html https://web.archive.org/web/20240719092417/http://uniforumch...
- transpute 2y ago> it'd sure be nice to have the presentation on video form March 2025 presentation by the same author, "Seat belts and Airbags for bash" slides: http://uniforumchicago.org/slides/bash_2025-03-25.pdf http://uniforumchicago.org/slides/bash_2025-03-25.pdf video (87m): https://www.youtube.com/watch?v=DvDu8_A2uhs https://www.youtube.com/watch?v=DvDu8_A2uhs
- pottmi 2y agoHere is a https link to the presentation and the stringent.sh library: https://github.com/pottmi/stringent.sh https://github.com/pottmi/stringent.sh
- degamad 2y agoNot down, just not on https. http link works just fine, but browser redirects to https by default.
- smartmic 2y agoStrange that PowerPoint was used for the slides. That's pretty much at the complete opposite end of the software spectrum to GNU Bash.
- transpute 2y agoThanks to WSL, bash is ̶a̶v̶a̶i̶l̶a̶b̶l̶e̶ ̶o̶n̶ shipped with Windows.
- rasjani 2y agoGit also ships bash for windows and doesn't require WSL. Can be even set as a default shell for OpenSSH so you can just ssh into windows bash...
- fluidcruft 2y agobash has been available on Windows since at least before the mid '90s.
- ta1243 2y agoYes I remember using cygwin back in 2004ish to provide bash when I had to use a windows pc at work (very briefly)
- fluidcruft 2y agoI was a co-op at a company in the 90s that specialzed in mechanical simulation of virtual prototypes. The software was primarily used on Unix (most of us used SGI boxes) but there was also a Windows port for smaller jobs and laptop use and (at least the dev environment) was all built on Cygwin.
- hexagonwin 2y agoMaybe it was written on OpenOffice or something and saved to ppt(x)? The linked file is PDF though.
- degamad 2y ago
- ndsipa_pomu 2y agoGreg's BASH Wiki is the best resource that I've found for tips, tricks and discussion of the many, many mistakes that BASH almost encourages people to make. https://mywiki.wooledge.org/BashGuide https://mywiki.wooledge.org/BashGuide Also, ShellCheck is an invaluable resource to use on all your scripts. When it complains about something, read up on why it doesn't like it and then decide to either fix your code or put in an exception to tell ShellCheck to ignore that particular issue for the next line. https://www.shellcheck.net/ https://www.shellcheck.net/
- pmarreck 2y ago+1 for shellcheck recommendation, it's fairly essential if you want to be good at Bash
- wyclif 2y agoIs shellcheck written in Haskell?
- ndsipa_pomu 2y agoYes, it's mentioned on their homepage - "written in Haskell, if you're into that sort of thing." https://www.shellcheck.net/ https://www.shellcheck.net/
- vivzkestrel 2y agoAnyone knows a good book for bash scripting 5.x ???
- deleted 2y ago[deleted]
- pmarreck 2y agoI've been on a longish search for a bash replacement (or at least "extra substitute") in the realm of "more complex commandline scripting" (functions, utility scripts, etc.). Naturally, every option is a set of different compromises. I think I've finally settled on Lua- It's small, coherent, surprisingly fast (especially with LuaJIT) and has the "virtually no startup cost" I was looking for (which ruled out, for example, Elixir for a lot of things). And, I've finally figured out how to bang my nix-darwin flake.nix config in a way that gets it AND a bunch of popular libraries installed together and all seeing each other. Wondering what others have found to address this. Or if they just stuck with Bash, since it's just not going away anytime soon.
- falcor84 2y agoHave you tried NGS (https://ngs-lang.org https://ngs-lang.org)? I found its approach of giving you that power while remaining shell-focused to be very refreshing.
- esafak 2y agoSomebody ought to package it for Linux OSs. I filed a ticket. It has similar aims to https://www.nushell.sh/ https://www.nushell.sh/
- pmarreck 2y agointeresting. I've actually already written a lot of the functionality I see here as bash (and other) functions, lol (things like log, filter, debug, retry, repeat, map, fetch (a URL, with retry)... etc.). (things like: enumeration functions, table pretty-printing, etc.)
- ilyash 2y agoHi. Author here. > I've actually already written a lot of the functionality I see here as bash (and other) functions That's exactly the reason these are part of stdlib. No reason for everybody to reimplemnt these with slight variations and copy it around.
- k3vinw 2y agoOne of the first things I do is turn on errexit and pipefail options, but trapping ERR and combining with LINENO to catch silent exits is brilliant!
- pottmi 2y agoYou will like the final version of the traperr ERR function. It looks to create a "stack trace" type dump of where you are in the script when it fails. See it here: https://github.com/pottmi/stringent.sh https://github.com/pottmi/stringent.sh
- usrnm 2y agoPlease, don't do any advanced shell scripting, period. I've had enough :(
- dionian 2y agohistorically, I did not write a lot of code in python - but since an LLM can, now i especially have no problem doing more scripts in it. it's so much more scalable than bash and pretty much ubiquitous.
- Red_Tarsius 2y agoNew readers might enjoy the tale of Emperor Sh and the Traveller: https://sanctum.geek.nz/etc/emperor-sh-and-the-traveller.txt https://sanctum.geek.nz/etc/emperor-sh-and-the-traveller.txt
- skydhash 2y agoI have followed the advice in this story for all my scripts. They are just better interfaces to collection of tools that already exists, not new tools. I write them when the subproblems are already solved by specific programs and the coordination does not require complex data transformation.
- stackedinserter 2y agoThe most valuable skill in bash scripting is to know when to stop writing bash and switch to a proper language before the script turns to unmaintainable chunk of unmanageable complexity.
- Philpax 2y agoThe mark of an advanced shell scripter is knowing not to do advanced shell scripting. (This statement primarily applies to existing stringly-typed scripting languages, which are nightmarish to maintain and debug. PowerShell, nushell, or similar solutions have a much higher complexity ceiling.)
- transpute 2y ago2025 update of this 2006 presentation has a better title, https://news.ycombinator.com/item?id=43714928 https://news.ycombinator.com/item?id=43714928 Seat Belts and Airbags for bash
- pragma_x 2y agoThank you for linking this. I really want to reach for that pun and suggest: "Seat Belts and Airbags for bash safety" as an even better title.
- rascul 2y agoAren't TCL and Perl stringly-typed scripting languages?
- aborsy 2y agoIsn’t it better to replace bash scripting with Python or similar, unless the script is simple?
- dec0dedab0de 2y agoyes, unless you need it to run somewhere that you know only has bash.
- mdaniel 2y agoThis trope comes up every time bash is mentioned, without fail. Unless your team enjoys reading this, then no, a general purpose programming language is not a good replacement for what is effectively a "subprocess orchestration language": from subprocess import run, PIPE home = os.getenv("HOME") try: os.chdir(f"{home}/dev") except FileNotFoundError: sys.exit(1) out = run(("git ls-remote https://github.com/%(repo)s refs/tags/%(tag)s" % {"repo": shlex.quote("myorg/myrepo"), "tag": shlex.quote("v1.2.3+deadbeef")}).split(" "), stdout=PIPE, stderr=PIPE) The line noise is outrageous as compared to a language built for changing directories and running commands That's not even getting into the pty portion, where the progress of the output isn't visible until the end of it, which is terrible DX
- aborsy 2y agoThis falls under the case “unless the bash script is simple “. If you consider more complex tasks, bash quickly gets unwieldy, and the situation is reversed. Pythons has a lot of advantages, including full flexibility, error handling etc.
- BeetleB 2y agoIn xonsh[0], that would be: cd $HOME/media git ls-remote ... (Not sure about the equivalent of shlex.quote, but in the worst case, you can just use "from shlex import quote as q" or something). So yes, there are good alternatives to bash - even Python based. [0] https://xon.sh/ https://xon.sh/
- Too 2y agoNice rube goldberg machine. Apart from imports, that is equivalent to repo = "myorg/myrepo" tag = "v1.2.3+deadbeef" out = check_output(["git", "ls-remote", f"https://github.com/{repo}", f"refs/tags/{tag}"], cwd=os.path.expanduser("~/dev"), stderr=PIPE) Converting exceptions to exits is an anti-pattern that hides the source of the error, f-strings has been a thing for 10 years and argument quoting happens automatically. Progress of output isn't visible in bash either when you capture output with $(), unless you "tee", which opens up another can of "pipefail"-worms.
- digitalsushi 2y ago15 years ago my 'mentor' taught me buggy_command || : and 15 years later i am still begging people not to litter our deployment scripts with this pattern. i call this "the penny in the fusebox"
- PeterWhittaker 2y agoThat. Is. Evil. Nuke it from orbit, or something like that.
- pottmi 2y agoI am the author of this presentation. Feel free to ask me questions and send me corrections to the pdf and youtube video. Here is are the slides: http://uniforumchicago.org/slides/bash_2025-03-25.pdf http://uniforumchicago.org/slides/bash_2025-03-25.pdf Here is the recording of the video: https://www.youtube.com/watch?v=DvDu8_A2uhs https://www.youtube.com/watch?v=DvDu8_A2uhs Here is the stringent.sh library that is shown in the presentation: https://github.com/pottmi/stringent.sh https://github.com/pottmi/stringent.sh
- transpute 2y agoThanks for carrying a 20 year torch on bash maintainability!
- pottmi 2y agoIt is what I advise people that want to make a presentation to give to their local LUG. Do the presentation on something "evergreen" that will last a long time. File permission, regular expression, /proc file system, ... Dig into the details and anytime you are surprised by something make a new slide. Also make "Cookbook" slides. pretty soon you have 30 slides and it is enough for a full presentation.
- Scipio_Afri 2y agoIs there an https link to this pdf? So rare to see http nowadays.
- pottmi 2y agoI contacted the guys that run the site and asked them to add https. I will throw the pdf on my gitlab account that has the stringent.sh script. https://github.com/pottmi/stringent.sh https://github.com/pottmi/stringent.sh
- PeterWhittaker 2y agoGreat presentation. I've been writing bash for waaaay too long, and, while I nodded and said yup, yup, a few times, I also learned some new tricks, so thank you! The social graces having been observed, if you were to update this presentation to reflect modern bash, and especially reference variables, what would be your top 3 additions? (I am a big fan of reference variables. They make it possible to, among other things, do some funky things that would otherwise require liberal use of eval, which I eschew. Figuring out how to ensure that the target of a reference variable was in fact an associative array while running under `set -u` was a trick of which I am proud. Note: what I did works and isn't totally ugly, there may be a better way, YMMV, IANAL, etc.) Second Q, if you will permit: Given the memory leaks in associative array management that have been corrected over the last several years, what are your thoughts on a) whether or not bash should have ever gone that route, and, potentially more controversially, b) the current state of bash maintenance? (I'm not going to ask about embedding multiple levels of ${...#...} or ${...#...}, because even if it worked, readability would tend to 0 very, very quickly. I'd rather be repetitive and readable and maintainable. Well. Most of the time.)
- 1vuio0pswjnm7 2y agoLinux distribution maintainers believe Bash is an inferior shell for scripting. It may be a superior shell for interactive use, depending on personal preference. No one is prevented from using whatever shell they prefer for whatever purpose. For example I prefer to use a smaller, slightly modified scripting shell for interactive use. Some folks prefer to use a large, interactive shell for scripting.
- transpute 2y agoAny recommendation on small shells? ash?
- deleted 2y ago[deleted]
- 1vuio0pswjnm7 2y agoChoice of scripting shell is personal preference. Preferences may differ amongst computer owners. For example, I prefer NetBSD sh. On Linux I use a slightly modified Dash. As for the preferences of others, I note the default scripting shell on the largest Linux distributions is not Bash. It is of course Dash, which is derived from NetBSD sh, which is derived from the Almquist shell (ash). Indeed, ash is a popular choice for scripting. It is smaller and faster than Bash.
- alganet 2y agoWhat an interesting, eye-catching subject matter that certainly can bring an old programmer's attention to more productive endeavours than messy ideological discussion.
- bjfkdyvydjvgi 2y ago[flagged]