On my desktop ubuntu host if I run a script with only the line

echo $SHELL

it prints


But on a different host running busybox, if I do the same thing I get



And I have noticed that if I create scripts on my ubuntu box and run them on the busybox host then sometimes I get different behavior.

What I would like to do is create a shortcut on my ubuntu desktop to some terminal session that would run the Bourne Shell, /bin/sh, rather than the Bourne Again Shell, bash. Is that possible or is my thinking about this wrong?

  • There is a very good post about the topic on stackoverflow. – Simon Sudler Oct 15 '18 at 13:34

First of all, you should read about POSIX and different shell implentations. Then, if you need portability, try to write your scripts as POSIX-compliant as possible.

For testing your scripts to work with busybox, you can install and run the busybox default shell ash to check your scripts syntax to work with busybox:

sudo apt install ash
# non-posix function declaration (works in bash, but not in ash)
$ function test(){ echo Hello World; }
ash: 1: Syntax error: "(" unexpected
# posix-compliant function declaration (works in ash and bash)
$ test(){ echo Hello World; }
$ test
Hello World

But that might not be enough, as this will still use the GNU version of the default tools and has all your other installed programs, which are probably not installed with your busybox.

$ grep --version
grep (GNU grep) 2.25

If you have docker, you can run a busybox container with just its default tools:

docker run -it --rm busybox
$ grep --version
grep: unrecognized option `--version'
BusyBox v1.29.3 (2018-10-01 22:37:18 UTC) multi-call binary.
| improve this answer | |

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.