How to use Bash for sh in Ubuntu

To switch sh to bash (instead of dash, the default), reconfigure dash (yes, it’s somewhat counter-intuitive):

sudo dpkg-reconfigure dash

This will ask whether you want dash to be the default system shell; answer “No” (Tab then Enter) and bash will become the default instead (i.e. /bin/sh will point to /bin/bash).


There are multiple programs that implement the language of /bin/sh. On Ubuntu, /bin/sh is dash, which is designed to be fast, to use a small amount of memory, and doesn't support much more than the minimum expected from /bin/sh. On RHEL, /bin/sh is bash, which is slower and uses more memory but has more features. One of these features is the == operator for the [ conditional syntax. Dash supports [, which is a basic sh feature, but it doesn't have the == operator which is a bash (and ksh and zsh) extension.

You can switch your system to using bash. On Ubuntu, /bin/sh is a symbolic link to dash. You can make it a symbolic link to bash instead. Current versions of Debian and Ubuntu (and derivatives) make this an installation option of dash. To change it, run

sudo dpkg-reconfigure dash

and answer “yes” to keep dash as /bin/sh or “no” to switch to bash.

You can keep bash as /bin/sh, but it'll make your system a bit slower. It's even conceivable that some system script is incompatible with bash, although that's unlikely since bash is mostly a superset of dash.


For distributions which don't have an interface to choose between implementations of /bin/sh, here's how to switch to bash.

sudo ln -s bash /bin/sh.bash
sudo mv /bin/sh.bash /bin/sh

Keep a terminal open and check that you can still run some sh scripts after that. If you mess up this command, it'll make your system unusable. (By the way, the reason I used the multiple commands above rather than the straightforward-looking sudo ln -sf bash /bin/sh is that ln -sf is not atomic. In the admittedly unlikely case your computer crashed during this operation, you'd need to boot from rescue media to restore it. In contrast, mv is atomic.)

To restore dash as /bin/sh:

sudo ln -s dash /bin/sh.dash
sudo mv /bin/sh.dash /bin/sh

Note that if sh is /bin/bash by default on your distribution, switching to dash may cause scripts to fail, because bash has many more features than dash. Bash scripts should start with #!/bin/bash, and scripts starting with #!/bin/sh should not use bash-specific features, but distributions that ship with bash as /bin/sh may use bash-specific features in #!/bin/sh scripts that are specific to that distribution (it's ok as long as there's no expectation that users can switch to dash as /bin/sh and there's no expectations that these scripts work on another distribution).