Are dash, ash and sh script 100% compatible?
Solution 1
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.
Solution 2
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
Related videos on Youtube
user1115057
Im interested in learning how to do low level stuff like kernel, os, driver.... Thing i need to learn: Programming (i already know how to write in C, C++, but i still need to think like a programmer...).
Updated on September 18, 2022Comments
-
user1115057 almost 2 years
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.
-
Admin almost 12 yearsash is a striped down form of bash
-
Admin almost 12 yearsWhy 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
-
Admin almost 12 yearsCorrect, 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.
-
Admin almost 12 yearsYou can use the utility
checkbashisms
to test that your script is POSIX compliant. -
Admin about 4 years@daisy Why not
bash
everywhere? Because it isn't always the right tool for the job. Moreover, it's GPL. On top of that, it's quite a lot heavier thansh
.
-
-
user1115057 almost 12 yearsBut for script usage, they are compatible?
-
user1115057 almost 12 yearsAnd 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
-
Zlatko almost 12 yearsThey 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.
-
user1115057 almost 12 yearsnever intended to use bash with sh or ash or dash. What are those obscure feature?
-
Joe almost 12 yearsI do not think ash is POSIX compliant but do not quote me on that
-
lynxlynxlynx almost 12 yearsmany 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 ...).
-
user1115057 almost 12 yearsI know that there will be difference in tool. But before worrying about that, I need to first start to write portable code, then after I can worry about the tool not exactly the same.
-
muru over 8 yearsThey might have busybox ash.
-
Zoran about 4 yearsThat said, there are many systems which don't have
bash
either. -
Zoran about 4 yearsThere are also some extremely rare systems where
sh
is a symlink tocsh
, which breaks a lot of stuff.