0

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

echo $SHELL

it prints

/bin/bash

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

/bin/sh

printed

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?

arcomber
  • 173
  • 1
  • 7

1 Answers1

0

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
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.

ash
$ 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.
pLumo
  • 26,947