Ubuntu: What is the difference between #!/bin/sh and #!/bin/bash?
Channel: Roel Van de Paar
Date: 17/06/2019

Ubuntu: What is the difference between #!/bin/sh and #!/bin/bash?


The Question: if I write,
#!/bin/bash
echo "foo"
or
#!/bin/sh
echo "foo"
both yields same. I have seen some scripts starting with #!/bin/sh or #!/bin/
bash. Is there any difference between them?

Solutions Sample (Please watch the whole video to see all solutions, in order of how many people found them helpful):

== This solution helped 204 people ==
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 https://
wiki.ubuntu.com/DashAsBinSh. 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.

With thanks & praise to God! With thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user ??????? (https://askubuntu.com/users/907046), user thomasrutter (https://askubuntu.com/users/54256), user reverendj1 (https://askubuntu.com/users/53455), user Rahul Virpara (https://askubuntu.com/users/40166), user muru (https://askubuntu.com/users/158442), user dessert (https://askubuntu.com/users/507051), user Chan-Ho Suh (https://askubuntu.com/users/43660), user AnkiF (https://askubuntu.com/users/368652), and the Stack Exchange Network (http://stackoverflow.com/questions/141928). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything should be amiss at Roel D.OT VandePaar A.T gmail.com.