4 ms·
Advanced shell features will not run with dash, which is (almost) strict POSIX. They also fail with busybox. There are many subtle differences between BASH an
by chasil 2y ago
Advanced shell features will not run with dash, which is (almost) strict POSIX.
They also fail with busybox.
There are many subtle differences between BASH and Korn, so much will not run without rewrite on Android's mksh.
Because you have not needed portable scripts yourself does not imply that the need is not vast.
- 3np 2y agoClassic IAGNI/YAGNI conflation.
- Etheryte 2y agoIn many cases, the fact that it's far from trivial to figure out whether your script is portable or not, makes them not portable for practical intents and purposes. I would say that for most people and most use cases, shell scripts are write once and hope you never have to edit them again, and even knowing one way of comparing values may be problematic while another might not be is beyond the given pay grade.
- dredmorbius 2y agoYou can of course test portability by testing, or simply writing, your script against a POSIX-only shell interpretation. It's a lot easier to change a shebang (#!/bin/ash -> #!/bin/sh) than to rewrite the full script during a firefight. One might even suggest "/bin/bash considered harmful".
- Joker_vD 2y agoOne also may suggest "/bin/sh considered harmful". Does the rest of the world have to suffer just because Solaris can't be arsed to upgrade its tooling (much of it is very tentatively POSIX-compliant anyhow) so they block any new additions to the /bin/sh features in the POSIX?
- chasil 2y agoThe dash shell compiles to 80k on an i386, which is viable for embedded applications. The POSIX shell was standardized in view of the original Korn shell, which could compile to 64k on Xenix 286. The functionality was reduced in an effort to increase code maintainability. Edit: "A lot of effort was made to keep ksh88 small. In fact the size you report on Solaris is without stripping the symbol table. The size that I am getting for ksh88i on Solaris is 160K and the size on NetBSD on intel is 135K. "ksh88 was able to compile on machines that only allowed 64K text. There were many compromises to this approach. I gave up on size minimization with ksh93." https://m.slashdot.org/story/16351 https://m.slashdot.org/story/16351
- dredmorbius 2y ago<https://news.ycombinator.com/item?id=41682985 https://news.ycombinator.com/item?id=41682985> It's hardly just Solaris.
- deleted 2y ago[deleted]
- pastage 2y agoThis can be said of most programming, in Java, C++, golang, Pascal and Ruby I have been on projects that could not compile. The dependencies are so out dated a complete rewrite is easier. I do not find bash worse or better. You just do alot more with less lines in it.
- chasil 2y agoIf you use arrays, you cannot use dash.
- cmsj 2y agoThe correct solution here is to pick one of the following options: 1) Write a bash script and put /bin/bash in your shebang 2) Write a POSIX shell script and integrate checkbashisms into your editor. Neither is more correct than the other.
- chasil 2y ago3) #!/bin/dash
- flir 2y ago#!/usr/bin/env dash I mean, if we're targeting portability...
- dredmorbius 2y agoI believe many Linuxes still symlink /bin/sh -> /bin/bash, so the shebang itself won't save you. Debian's assignment of /bin/dash as the default /bin/sh is relatively recent (at least for those who've been running Debian since the 1990s). I virtually exclusively write Bash scripts for my own use. I've been bit by bashisms however, and at the very least don't casually dismiss the concerns which are voiced against doing this. I'm also daily using systems which don't have a full Bash, and which really don't have the resources to run it (mostly storage, though other factors may be involved).
- yjftsjthsd-h 2y ago> Write a POSIX shell script and integrate checkbashisms into your editor. Suggestion: Use shellcheck. It will complain about bashisms if your script says #!/bin/sh and will also catch loads of other problems.