shell script to sort out the basics of <1>

A, shell script format
#! / Bin / bash
The first line is to specify the program to compile and run the script
comment is the beginning of a "#"

Second, the implementation of the script source, sh, bash,. / Execute difference scripts
1, "." Command point, is a point symbol (coming from the Bourne Shell) is the name of another source of
2, source command (from the C Shell and to) execute bash shell built-in commands
3, bash / bin / bash command sh powerful functions than
4, sh / bin / sh command
5, export can add, modify or delete environment variables, program for subsequent executions of use. At the same time, the important point is that the effectiveness of export and only once in the landing operation. Cancellation or re-open a window, given the environment variable export command does not exist.
$ PATH: export PATH = / bin / bash
difference between them 6, (point file name source bash sh ./ executed)
6.1: point source and execution are equivalent; that is the way are two ways to execute in the current shell the process of executing this script, instead of restarting a shell script is executed in the child shell process.
6.2: bash sh (can not execute permissions) two different executable file
./ (must have execute permissions) three implementation are equivalent; these three ways to restart the execution of the script is a sub-shell, in sub shell script is executed.
6.3: validation results:

[root @ localhost ~] # name = dangxu // definition of a general variable
[the root @ localhost ~] # echo $ {name}
dangxu
[the root @ localhost ~] # CAT test.sh validation script // instantiate title. /*.sh
#! / bin / SH
echo $ {name}
[the root @ localhost ~] # LS test.sh -l // validate executable scripts
-rwxr-xr-x 1 root root 23 Feb 6 11:09 test .sh
[root @ localhost ~] # ./test.sh // the following three commands to prove a conclusion
[root @ localhost ~] # SH ./test.sh
[root @ localhost ~] # bash ./test.sh
[root @ localhost ~] #. ./test.sh // the following two commands proved Conclusion 2
dangxu
[root @ localhost ~] # Source ./test.sh
dangxu
[root @ localhost ~] #

Guess you like

Origin blog.51cto.com/14294148/2434425