1. Source command usage: Sourcefilename
Purpose: read and execute the command in filename in the current bash environment. This filename file may not have "execution permission"
Note: This command is usually replaced by the "." command.
Example: sourcebash_profile . Bash_profile is equivalent to both.
The source (or vertex) command is usually used to re-execute the modified initialization document.
The source command (from C shell) is the built-in command of bashshell.
The dot command is a dot symbol (from bourneshell ). Is the command in the sequential execution file.
2. SH and bash command usage: Shfilename Bashfilename
Purpose: Create a new shell in the corresponding bash environment to read and execute the command in filename. This filename file may not have "execution permission"
Note: The difference between the two is that they use their own shells to run files. Sh uses the "-n" option to check the syntax of shell scripts, and uses the "-X" option to track shell scripts one by one, the built-in variables of shell can be cleverly used to enhance the output information of the "-X" option.
3. command usage: ./Filename
Purpose: open a sub-shell to read and execute the command in filename.
The file must have executable permissions.
Note: When running a shell script, another command interpreter is started.
Each shell script runs effectively in a sub-process of the parent shell (parentshell. This parent shell refers to a process that provides command indicators to you on a control terminal or in an xterm window. shell scripts can also start their own sub-processes. these sub-shells (that is, sub-processes) Allow scripts to run multiple sub-tasks in the script in parallel and efficiently. the variable settings in the script are invalid in the parent process. The export in the script only acts on the location variable parameters of the script and Its subscripts. When passing parameters to the script, you can use this location variable to obtain parameters. They are:
$0: Script Name. This variable contains the address. You can use basename $0 get the script name.
$1: The first parameter
$2, $3, $4, $5,... and so on.
Specific variable parameters
Control Information about script running
$ # Number of parameters passed to the script
$ * Display all parameters passed to the script with a single string
$ ID of the script run
$! ID of the last process running in the background
$ @ Is the same as $ #, but it is enclosed by quotation marks and each parameter is returned in quotation marks.
$-Display the current options used by shell.
$? Displays the launch status of the last command. 0 indicates no error.
What is the difference between source filename and sh filename and./filename script execution?
1. When the shell script has the executable permission, there is no difference between using shfilename and./filename to execute the script .. /Filename indicates that the current directory is not in the path, and all "." indicates the current directory.
2. sh filename re-creates a sub-shell and executes the statements in the script in the sub-shell. The sub-shell inherits the environment variables of the parent shell, the new and changed variables created by the sub-shell are not brought back to the parent shell unless export is used.
3. sourcefilename: The command simply reads the statements in the script and runs them in the current shell. No new sub-shell is created. All statements for creating and changing variables in the script are saved in the current shell.
Example:
1. CreateTest. Sh script, content: A = 1
2. Execute chmod + xtest. Sh.
3. After running shtest. Sh, Echo $ A is blank because a = 1 is not returned to the current shell.
4. After running./test. Sh, the same effect will be achieved.
5. Run source test. Sh or. Test. Sh, And Then ECHO $ A, 1 is displayed, indicating that the variable A = 1 is in the Current Shell Article Source: http://blog.sina.com.cn/s/blog_6954b9a90101106v.html