There are several ways to execute the shell script
1, relative path mode, you need to first CD to the script path
[[email protected] tmp]# Cd/tmp[[email protected] tmp]#./ceshi.sh Script Execution succeeded
2. Absolute path mode
[[email protected] tmp]#/tmp/ceshi.sh script executed successfully
3. Bash Command call
[[email protected]/]# bash/tmp/ceshi.sh script executed successfully
4,. (space) A relative or absolute way
[Email protected]/]#. /tmp/ceshi.sh Script Execution succeeded
The difference in several ways
There is no difference between the first and the second, both of which require a script to be given in advance to execute permissions.
The third is to handle the script as a bash call, so the script does not need to have execute permission to execute.
The first three methods are to open a child shell in the current shell to execute the script content, when the script content is finished, the child shell is closed, back to the parent shell.
The fourth is to make the script content execute in the current shell, rather than opening the shell alone.
The difference between the open shell and the non-open shell is that the inheritance of environment variables, such as the current variable set in a child shell, is not handled by a special channel, and the parent shell is not visible.
When executed in the current shell, all environment variables that are set are directly active.
Validation
[Email protected]/]# cat/tmp/ceshi.sh Top
1. Pstree display in the first three modes of execution
├─sshd─┬─sshd───bash───bash───top │ └─sshd───bash───pstree
2. Pstree display under the fourth mode of execution
├─sshd─┬─sshd───bash───top │ └─sshd───bash───pstree
3. Verify the inheritance relationship and visible relationship of environment variable setting
Build two scripts, father.sh and subshell.sh. where father.sh calls subshell.sh
Execution results are
[[email protected]/]#/tmp/father.sh invoke script output as child shell V_ceshi value Father Execute script output V_ceshi value to son in the current shell
Several ways the shell script executes