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?
bashscriptsshshebang
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?
Best Answer
bash
andsh
are two different shells. Basicallybash
issh
, 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 invokesh
. In Ubuntu/bin/sh
used to link tobash
, typical behavior on Linux distributions, but now has changed to linking to another shell called dash. I would usebash
, 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 tobash
when it doesn't have to be.For more info, http://man.cx/sh, http://man.cx/bash.