Ubuntu – the difference between #!/bin/sh and #!/bin/bash


if I write,

echo "foo"


echo "foo"

both yields same. I have seen some scripts starting with #!/bin/sh or #!/bin/bash. Is there any difference between them?

Best Answer

bash and sh are two different shells. Basically bash is sh, with more features and better syntax. Most commands work the same, but they are different.

Having said that, you should realize /bin/sh on most systems will be a symbolic link and will not invoke sh. In Ubuntu /bin/sh used to link to bash, typical behavior on Linux distributions, but now has changed to linking to another shell called dash. I would use bash, as that is pretty much the standard (or at least most common, from my experience). In fact, problems arise when a bash script will use #!/bin/sh because the script-maker assumes the link is to bash when it doesn't have to be.

For more info, http://man.cx/sh, http://man.cx/bash.