linux shell of the difference between sh and bash

#! / Bin / sh & #! / Bin / bash Ku别

At the beginning of shell scripts often use a word to define what kind of sh interpreter to interpret the script.
    (1) #! / Bin / SH
    (2) #! / Bin / bash

Both differences are as follows:
1. Create test.sh script reads as follows:

#!/bin/sh
source pcy.sh #pcy.sh并不存在
echo hello


Execution ./test.sh, screen output:
   ./test.sh: Line 2: pcy.sh: No SUCH File or Directory
! So you can learn, in the case of # / bin / sh is, Source win, no the source code that runs behind .


Test.sh modify the first line of the script as follows:

#!/bin/bash
source pcy.sh #pcy.sh并不存在
echo hello

Executed again ./test.sh, the screen output is:
   ./test.sh: Line 2: pcy.sh: No SUCH File Directory or
    the Hello

the reason:

1. sh bash generally set to soft chain
      [Testing Work @ ZJM-CY-app46] $ LL / bin / SH
      lrwxrwxrwx-Nov. 1 the root 13 is the root. 4 2006 / bin / SH -> bash
2. In a general system which linux ( such as redhat), equivalent to execute the script calls using sh bash open the POSIX standard mode
3. that / bin / sh is equivalent to / bin / bash --posix
so, sh bash with distinction, in fact, there is no bash open posix mode except
if written in the first line #! / bin / bash --posix, implementation of the results with the #! / bin / sh is the same (posix follow specific norms, the code will no longer down to explain the program stops here!)

Original Address

Published 55 original articles · won praise 17 · views 80000 +

Guess you like

Origin blog.csdn.net/XuHang666/article/details/83270152
Recommended