[Solved] Ash Command Language Reference

I’m looking for a command language reference for the ash shell, but can’t seem to find such an animal.

Playing around in BusyBox, it appears to be very much like bash - environment variables, command aliasing, shortcuts, job control, expansion, et al. Considering this environment, I’m assuming ash is a cut down version of bash?

Can I also assume the bash reference manual is relevant to ash, or does there actually exist a specific reference for ash?

It’s been a lifetime since I did any shell scripting, but I have managed to cludge my way through a couple of init.d scripts mods to meet my specific needs, but it’s hardly efficient and heaven knows my code is more than a bit mangled. A reference doc would make it so much easier to understand and modify existing code.

busybox ash is a very basic implementation of a POSIX compliant shell as specified in the Single UNIX Specification, Version 4 (SUSv4), a (clone of the) successor of the original Bourne shell. In order to work on severely flash/ RAM constrained systems, it implements barely more than the minimum required by SUSv4 (its exact feature set is configurable during busybox' build process to a considerable extent).

The Bourne Again SHell is another successor basing on these principles of being a (mostly-) SUSv4 compliant system shell for interactive and non-interactive uses. As many other GNU tools, it emphasizes the convenience aspects (including interactive usage) and extends beyond the basic feature set mandated by POSIX, making it a superset (which might occasionally diverge from the standard) of a POSIX shell.

This extended feature set easily lulls the user writing (#!/bin/sh) shell scripts on systems using bash as system shell to assume the feature set of bash would be generally available on all POSIX systems, leading to portability issues ("bashisms") if these scripts are used on systems with different (more limited or standards adhering) POSIX shells used as (non-interactive-) system shell (e.g., all of the *BSD operating systems, the commercial Unices (Solaris, AIX, …) and particularly embedded systems, like e.g. OpenWrt). As a result, any POSIX/ SUSv4 compliant shell script should work fine on bash, dash, pdksh, posh, mksh, busybox ash, but a bash script (incorrectly using a #!/bin/sh shebang, instead of #!/bin/bash) will fail spectacularly when executed on a shell not offering these additional (non-standard) features.

For non-interactive uses, especially on -but not limited to- resource constrained devices, bash might be rather on the heavy side, in terms of disk size, memory requirements and startup time, which is a particular concern on lower end systems (especially while booting the system on a sysv like init system, which has to execute between dozens and hundreds of tiny initscripts to boot the system). Because of this, Canonical's Ubuntu (and later followed by Debian) has switched the non-interactive system shell (the shell used for executing #!/bin/sh 'shell' scripts) from bash to a smaller/ more limited/ faster shell (dash, another ash successor) in 2006. This has brought the danger of bashisms into a broader focus, as this exposed the lazy programming in thousands of (particularlly GNU derived) opensource projects.

While you can write shell scripts on a system using bash as /bin/sh, you should be aware of the common pitfalls and differences between a basic POSIX compliant shell and bash and should test your results on a variety of different SUSv4 compliant shells (e.g. dash, posh, pdksh/ mksh and busybox ash) before using #!/bin/sh as shebang. If in doubt, use #!/bin/bash instead (which will execute your script under bash, instead of a generic POSIX shell), obviously bash needs to be installed on the target system for this to work (which is not the case on OpenWrt, so here you really need to restrict yourself to the feature set described in SUSv4). Literature on programming in bash can still be a valuable resource, so are the shell specific chapters of the Single UNIX Specification, Version 4 (SUSv4).

3 Likes

So in a nutshell:

That’s an excellent response! Clarifies many things and points me exactly where I needed to go. Many, many thanks. I’ve been going in circles on this question.

1 Like

Hi.

I found that this link to "man7" pages contains a very useful guide to using this shell. Its not an exhaustive reference, but has all the basic information, and most importantly sticks to the basic features that are actually available in the openwrt shell. Its a nice complement to the openwrt documentation.

Link:
https://man7.org/linux/man-pages/man1/dash.1.html

Hope this helps.

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.

Thank you. Apparently I was being too specific in my searches. Why I didn’t think of the man pages :blush: I don’t know. Not seeing the trees because of the forest I guess.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.