top | item 35986327

(no title)

spyremeown | 2 years ago

>I would recommend learning and using sh unless you really need Bash.

I don't buy this argument. Ok, it's a standard, but sometimes it's a pain-in-the-hole standard. Bash augmentations lessen some of the pains, and it's just nicer. The only situation is if you're using busybox in a very limited system or you reeeeeally need your script to run on many difference unices, which let's be honest, is not that common nowadays.

discuss

order

JdeBP|2 years ago

All of this was covered in great detail in the 2000s, when Debian and Ubuntu switched /bin/sh to the Debian Almquist shell, which was basically POSIX-only with some 3 things that Debian people simply couldn't live without, and encouraged system scripts to use it. If you weren't around then, go and read the discussions. They're mostly still available, and they cover some important stuff that straw man counterarguments regularly miss.

The Debian people were concerned, for starters, with how much time the Bourne Again shell spent, at process initialization, setting up things for extensions and interactive features that were never employed in non-interactive "sh" mode; a significant cause for concern given how much of the system was executable shell scripts.

jmclnx|2 years ago

>with some 3 things that Debian people simply couldn't live without

Curious, what are the 3 things ?

But yes, people should always use sh (or ksh) for scripting as opposed to bash, why, it is far more portable to other systems.

synergy20|2 years ago

I do small embedded systems with busybox, even that I can squeeze in bash when I need that, it's about 1MB in size and gives a lot more than busybox's sh. Another option is Lua which is also great.

blueflow|2 years ago

> is not that common nowadays

Due to docker, minimalistic Linux'es have been more common, including trimmed-down versions of distros that would otherwise feature bash.

synergy20|2 years ago

bash is rarely the focus though, it really just costs 1MB in storage, which is nothing comparing to python,etc.

kaba0|2 years ago

> Bash augmentations lessen some of the pains, and it's just nicer

Both sh and bash are terrible, ugly hacks. Anything that requires more than 3 lines of them (including the #! line) should be written in a proper scripting language.

Though I do agree that cross-platformity to that level is rarely meaningful, and so things like python are just as likely available/can be made available.

wvh|2 years ago

My system Python tree is almost 1GB. That doesn't matter for desktop systems, but most software is published as container images these days and using a language like Python, Ruby or Perl for an image that doesn't already need it is pretty wasteful and pulls in a lot of extra dependencies.

I'm not sure there is a good alternative to sh/bash shell scripts as most dynamic languages have become pretty large dependencies these days.

slondr|2 years ago

Python or lua scripts which are mainly clumsy and overly verbose wrappers around shell commands are way, way worse than shell scripts.

sgarland|2 years ago

Until someone decides to write something that's only available in X version of Python. While there are certainly v4 and v5 bash-isms, they are far and few between compared to most languages.

...that said, having to support bash 3.2 for MacOS is a horrible thing.

jhbadger|2 years ago

AWK is part of the POSIX standard and is therefore on every UNIX-like. People really need to remember AWK exists and is a real, proper scripting language with a very sane syntax (it's not just for cryptic one-liners, really!)

ndsipa_pomu|2 years ago

Which version of python though?

yyyk|2 years ago

If you wish require some users to install an interpreter, you might as well go for Korn or a real programming language. If you want to use something that's portable and installed everywhere, that's POSIX sh (or at most dash-like level). Bash is in the poor middle which isn't good enough for either side, unless you really know what's your target and don't care about elsewhere.