I wanted to know whether scripts written for dash, ash, and sh are 100% compatible?

Are there any added features to dash or ash, or syntax change?

From what I heard, ash is a direct descendant of sh.

  • ash is a striped down form of bash – Joe Aug 7 '12 at 6:14
  • 4
    Source? I saw nothing that said that ash is related to bash – user1115057 Aug 7 '12 at 6:25
  • Why wouldn't people just submit patches to bash instead of creating all kinds of shells, that buffles me all the time. If you really want to know, read the manual, e.g man ash – daisy Aug 7 '12 at 6:36
  • 3
    Correct, it's not descendant from bash. It would be more precise to say they're descendant from sh (the original Bourne shell), but that's not fully correct either. – Zlatko Aug 7 '12 at 6:37
  • 1
    You can use the utility checkbashisms to test that your script is POSIX compliant. – donothingsuccessfully Aug 7 '12 at 17:37

The short answer is no, they're not 100% compatible.

But most of the shells are pretty close to the basic, so you would only rarely bump into inconsistencies. In fact, most shells differ not much by added syntax, but by some extra features like tab-completion and similar.

Also, dash is sort of a descendant of ash — or port from BSD to Linux, to be precise. And all of them should be descendants or different implementations of sh. In fact, sh is on most systems just a symlink to bash, dash or something else. What matters is POSIX compliance — and when you write scripts according to the standards, you won't run into problems.

The difference between those shells is in optimizations and performance. They're less feature-rich then bash, but they are fully legitimate shells. Bash is feature-rich for interactive work, but uses more memory, for example.

| improve this answer | |
  • But for script usage, they are compatible? – user1115057 Aug 7 '12 at 6:36
  • And about the POSIX compliance, even if I follow that standard, if a script is written for Bash, I dont think it will run on any sh or its descendant – user1115057 Aug 7 '12 at 6:37
  • They should be compatible with each other if you're not using some obscure features. But if you use bash script, you might run into more troubles. – Zlatko Aug 7 '12 at 6:41
  • never intended to use bash with sh or ash or dash. What are those obscure feature? – user1115057 Aug 7 '12 at 6:42
  • 1
    many of bash's newer features are additions over POSIX, so it is increasingly likely you will write unportable code if you're using them. IIRC even the [[ ]] construct is not in sh. Also beware, that if you're not writting a pure shell script, difference in tools come into play as well (different versions of sed, grep, awk ...). – lynxlynxlynx Aug 7 '12 at 11:44

It should be mentioned that on some systems, notably Debian, /bin/ash is not available:

$ type ash dash
bash: type: ash: not found
dash is /bin/dash
| improve this answer | |
  • 2
    They might have busybox ash. – muru Dec 25 '15 at 16:35
  • That said, there are many systems which don't have bash either. – Tripp Kinetics Jun 9 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.