Somebody please tell me what's the difference between between #!/bm/bash and #!/bin/sh and links to get better idea please, and why we have to put it at the beggining of a script?
Asked
Active
Viewed 561 times
-1
-
When you set the first line in a script to `#!/bin/whatever` you are setting the *command interpreter* for that file to `/bin/whatever`. So when you set it to `#!/bin/sh` you are setting the command interpreter for the file to whatever `/bin/sh` is (usually POSIX shell, dash, or bourne shell). When you set it to `#!/bin/bash` you are saying, *"use bash to interpret the file"*. Nothing more, nothing less. – David C. Rankin Oct 15 '16 at 02:32
-
`/bin/sh` is never the Bourne shell on a POSIX system, because the Bourne shell is not POSIX-compliant. – chepner Oct 15 '16 at 14:19
2 Answers
0
bash
and sh
are two different shells. Basically bash
is sh
, with more features and better syntax.
From the bash(1) man page:
If
bash
is invoked with the namesh
, it tries to mimic the startup behavior of historical versions ofsh
as closely as possible, while conforming to the POSIX standard as well.
You have to put on the first line, to signify that the script should always be run with bash, rather than another shell.

jrbedard
- 3,662
- 5
- 30
- 34
0
One runs the script in a sh
shell and the other runs in a bash
shell.
See the Difference between sh and bash.

Gerard Roche
- 6,162
- 4
- 43
- 69