4 ms·
> No need for bash scripts Friends don't let friends write shell scripts targeting bash. For context: Bash is not available|installed everywhere, and has some
by stephenr 11y ago
> No need for bash scripts
Friends don't let friends write shell scripts targeting bash.
For context: Bash is not available|installed everywhere, and has some inter-version weirdness.
Write clean, posix-compliant shell scripts (i.e. target /bin/sh commonly referred to as bourne shell) and you're in a much better position.
On Debian your script will be run by Dash, on OS X it will be run by Bash, on Ubuntu or RedHat it could be different again, but the point is, they are specifically running in POSIX mode, so that you get reliable, reproducible results across systems and even across Bash versions.
- peatmoss 11y agoYou're getting downvoted to oblivion, but I'm old enough to remember not being able to take bash for granted. The default shell on some modern systems (OpenBSD for example) comes to mind as well. I feel this battle has mostly been lost, however.
- stephenr 11y agoHN coolkids downvoting advice that makes software more portable and reliable. What a fucking shock.
- 9912891 11y agoThey use bash as a service. It's integrated in node.js 2041.4.1.
- privong 11y ago> HN coolkids downvoting advice that makes software more portable and reliable. What a fucking shock. A little more verbosity on the advice might have helped. I wouldn't have properly understood you were saying without @peatmoss's reply. So without the context, your original comment just seemed like knee-jerk bash-bashing.
- slavik81 11y agoUnless you've actually tested it with a shell other than bash, you should be marking it as bash. Otherwise it's likely it will not actually be portable between shells, and you will have made your software less reliable. I've encountered many scripts written by developers on Fedora that totally fail over when run on Ubuntu specifically due to using #!/bin/sh when they really required #!/bin/bash.
- stephenr 11y agoUnless you've tested it as a shell script you should be marking it as a recipe for a banana cream pie. I specifically said "Write clean, posix-compliant shell scripts" Do the same developers write Java code in a .cpp file and wonder why it doesn't work? Or put <?php tags in a .erb template? Yes, you need to test to make sure that you wrote the correct things.
- pavanky 11y agoDefault on debian is dash.
- lorenzhs 11y agoBut bash is installed by default if I'm not terribly mistaken, and it's classified as an essential package. If you put in a bash shebang, it should work.
- pavanky 11y agoI have seen several people use #!/bin/sh and write bash code. This is going to break on debian machines when you do ./foo If more people used #!/usr/bin/env bash, it wouldn't be that big of a deal.
- stephenr 11y agoAnd they would have non portable code. If they wrote posix compatible shell scripts it wouldn't be any big deal because they'd just work.
- marcoperaza 11y agoThere's like five comments from you in this thread and you seem very adamant about people not writing bash scripts. Have you considered that not everyone has the same requirements? Maybe they don't care about targeting systems that don't have bash installed. In that case, they can use the myriad of enhancements that bash offers to improve their productivity and happiness.
- JdeBP 11y agoAnd, this page being news about Ubuntu, one should note that this has been true for Ubuntu for fast approaching a decade, now; Debian having followed in the footsteps of Ubuntu, in this regard. * https://wiki.ubuntu.com/DashAsBinSh https://wiki.ubuntu.com/DashAsBinSh * https://wiki.ubuntu.com/DashAsBinSh/Spec https://wiki.ubuntu.com/DashAsBinSh/Spec * https://lists.debian.org/debian-release/2007/07/msg00027.html https://lists.debian.org/debian-release/2007/07/msg00027.htm...
- notatoad 11y agoEverything old is new again - distros targeted at running inside docker containers (like Alpine) are shipping without bash. Not taking bash for granted is still a good plan.
- kps 11y agoAnd test them on a shell that isn't bash. Even with the --posix option bash accepts non-standard bashisms, particularly the execrable 'extension' of '>&'.
- bryanlarsen 11y agoThat's why I always put "#!/usr/bin/env bash" at the top of my scripts. Most were written to be portable, but unless it's been well tested, it's best to consider it not portable. Fail early and predictably rather than in strange ways.
- zzz157 11y agoDepends on the use case. There are cases where I don't know how I'd live without arrays/associative arrays. Performant regex matching is also quite nice.
- ionelm 11y ago> For context: Bash is not available|installed everywhere, and has some inter-version weirdness. Can you cite some sources here? No one knows what you're talking about.
- nailer 11y agoNon-OSX BSDs don't include bash, some things like the ... operator don't work on older versions of bash. Many people, especially Solaris and BSD folk, don't like bash scripts, and want you to write shell scripts in Bourne shell instead. Many other people, who code on OS X and deploy on Linux, enjoy the extras bash adds, and only deploy on platforms that include bash.
- sfilipov 11y agoI think your last point is important. I don't think shell script writers should be concerned about Solaris/BSD if they are confident that they will use their scripts only in environments where bash is available.
- stephenr 11y agoThe bash COMPAT page? http://tiswww.case.edu/php/chet/bash/COMPAT http://tiswww.case.edu/php/chet/bash/COMPAT Also, just because you may not know what I'm talking about, don't assume no-one else does.
- ionelm 11y agoSorry, I meant "no one who replied to you knows what you're talking about". Still, that list don't tell much about potential breakages. Are you actually complaining about bash having too many features or are there actual breakages? Please illustrate with examples, not links to tedious changelogs and ad-hominems.