Introduction of the. sh file
. SH is a Linux script file, and we can execute some commands through . SH , which can be understood as a. bat batch file for Windows.
Second, point command (.)
The . Command and source are the same command, which can be understood as the abbreviation for source , the abbreviation Point command .
Iii. sh/base/source/. command to perform the difference between. sh files
If there is a file test.sh, the script content is as follows
#!/bin/bashecho "Step 1 Sleeping"+echo "Step 2 Sleeping"200
Then, now do the following 4 ways:
1,./test.sh
2, SH test.sh/bash test.sh
3,. test.sh
4. SOURCE test.sh
What's the difference between them?
1, the first way is to execute the script itself in the current shell, That is to say test.sh as a file execution, at this time we need to have test.sh permission (x permission), and when we execute this command, there are 2 new processes running, one is test.sh, one is sleep, if we do the first sleep, press CTRL +c terminates the script, test.sh and sleep are terminated together, and the second sleep is not executed because the entire test.sh run has been terminated.
Tip: Assume that this test.sh file is in the user directory, not for . Messed up, actually ./ The meaning can be understood as running the. SH script or program in the current directory, this effect and ~/test.sh is the same effect, where ~/ represents the user directory
2, the second way, is to create a new shell to execute test.sh script inside the command, do not need to execute permissions, have Read permission (r permission), in the execution of this command, there are 2 new processes running, one is bash, one is sleep, if you perform the first sleep press CTRL + C,bash is terminated, the result is the same as the first, and the second sleep will not execute.
Tip: Bash is a reinforced version of SH, or it can be said that SH is a subset of bash, and running. sh files with these two commands is basically the same effect.
3, the Third Way, is in the current shell execution test.sh inside the command, do not need to execute permissions, have Read permission (r permission) can, in the execution of this command, only a new process is running, that is, sleep, if the first sleep by pressing CTRL + C to terminate, Then the second sleep runs until all the script commands are executed.
4, the fourth way and the third way of the same.
Above transfer from: http://www.zengdongwu.com/article3.html
Linux under sh/bash/source/. Command Differences (RPM)