1

I am trying to make a shell script that runs on a widest variety of *nix systems. So, if I wrote a bash script backwards compatible with old versions of the shell, but what if bash wasn't on the system? For example, is there another commonly used shell for embedded hardware? Or what did we use before bash was cool?

I'd like a simple script that helps me automate a wide verity of *nix systems, both old and new. More and more *nix systems are lumped into the "Internet of Things", and I want to write some highly-compatible home-brew scripts that can also work with these devices. (Which is why I started with Bash.)

HulkBash
  • 13
  • 3
  • dash is more posix, more minimal, and arguably more ubiquitous. but tbh, i don't get this argument. everything's connected to the internet now, and as long as you're connected to the internet, any piece of open source software is available. – Petr Skocik Feb 10 '16 at 15:41
  • @PSkocik Thanks for the reply, let me add more context – HulkBash Feb 10 '16 at 15:42
  • @PSkocik I work on lots of systems that are not connected to the Internet and never will be – Eric Renouf Feb 10 '16 at 15:43
  • 4
    @HulkBash You could probably use `/bin/sh` as your shell and let each system implement that how they see fit, so long as you stick to POSIX syntax that will be about as portable as you're likely to get – Eric Renouf Feb 10 '16 at 15:44
  • @EricRenouf you should write that up as an answer, the choice of shell is only one aspect of it, the other is sticking to POSIX (and potentially other) standards within that choice. – EightBitTony Feb 10 '16 at 15:49
  • Use the `#!/bin/sh` she-bang and send things to shellcheck.net (or its offline version) to lint for non-POSIX things. See also `checkbashism` from Debian, and [Portable Shell Scripting](https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/html_node/Portable-Shell.html) in autoconf manual. Side note: some features like `local` are present in most modern `/bin/sh`'s (\*ksh/\*ash) but neither POSIX nor Bourne has it. – Mingye Wang Feb 10 '16 at 19:06

2 Answers2

7

If you're looking for portability, you can bet that /bin/sh will be on most every system, though different platforms will implement it differently (e.g., on Ubuntu it links to dash and on Fedora it links to bash). Something will be there though.

If you use that and write your scripts in POSIX compliant ways you'll have your best shot at being portable.

Eric Renouf
  • 18,141
  • 4
  • 49
  • 65
0

The most common is /bin/sh. It's lighter than bash, that's why it's implemented on most embedded Linux-based systems.

muru
  • 69,900
  • 13
  • 192
  • 292
KhaimovMR
  • 121
  • 3
  • 4
    There's a non-trivial amount of systems out there where `/bin/sh` **is** bash. See e.g. http://unix.stackexchange.com/questions/44836/when-sh-is-a-symlink-to-bash-or-dash-bash-limits-itself-to-posix-compliance-so – MSalters Feb 10 '16 at 15:55