Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
346
rated 0 times [  346] [ 0]  / answers: 1 / hits: 823567  / 2 Years ago, tue, august 2, 2022, 4:12:09

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?


More From » bash

 Answers
4

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.


[#38125] Tuesday, August 2, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irtuallyefu

Total Points: 429
Total Questions: 97
Total Answers: 119

Location: Hong Kong
Member since Tue, Oct 19, 2021
3 Years ago
irtuallyefu questions
;