Combing the basic knowledge of shell script & lt; I & gt
I. shell script format
#! / bin/bash
The first line is to specify which program to compile and execute the script
The comment begins with a "#"
Second, the difference between script execution source, sh, bash,. / execution script
1. The dot command is just a dot symbol (from Bourne Shell) is another name for source
2. The source command (from C Shell) executes the built-in commands of bash shell
3. Bash / bin/bash command is more powerful than sh.
4. Sh / bin/sh command
5. Export can add, modify or delete environment variables for use by subsequent programs. At the same time, it is important that the effectiveness of export is only limited to that login operation. Log out or reopen a window, and the environment variables given by the export command no longer exist.
Export PATH=/bin/bash:$PATH
6. (click source bash sh. / file name for execution) the difference between them
Point and source execution are equivalent; that is, both execution methods execute the script in the current shell process, rather than restarting a shell and executing the script in the child shell process.
The execution files of 6.2:bash sh (which can be executed without permission) are different.
. / (execution permission is required) the three execution methods are equivalent; all three ways to execute the script are to restart a child shell and execute the script in the child shell.
6.3: verification result:
[root@localhost ~] # name=dangxu / / define general variables
[root@localhost ~] # echo ${name}
Dangxu
[root@localhost ~] # cat test.sh / / validation script to instantiate. / * .sh in the title
#! / bin/sh
Echo ${name}
[root@localhost ~] # ls-l test.sh / / verify that the script is executable
-rwxr-xr-x 1 root root 23 Feb 6 11:09 test.sh
[root@localhost] #. / test.sh / / the following three commands prove the first conclusion
[root@localhost ~] # sh. / test.sh
[root@localhost ~] # bash. / test.sh
[root@localhost] #. . / test.sh / / the following two commands prove conclusion two
Dangxu
[root@localhost ~] # source. / test.sh
Dangxu
[root@localhost ~] #