Two methods
- Start a new shell and execute the shell scripts.
- Shell scripts at the moment.
The scripts that brings up another shell will be added to the front of the scripts file.
#! /bin/sh
The first approach is to point out the shell scripts program before the shell script file (that is, our shell) and then open the file with the permission to execute it as usual, or call a shell to explain the text file test.sh.
$ test.sh $/bin/sh test.sh $ (. test.sh;) $ exec test.sh
The second method is to use the command "." or source to execute.
$ . test.sh $ source test.sh $ {test.sh;} $ Eval '. Test.sh '
The difference is that some assumptions are only counted in this shell, and the other shell is another irrelevant world, that is, the setting of the variables in the script that is executed in the first way, does not affect the original shell variables. This is important. Ksh does not have the source command, so it is best not to use source. The brackets () denote the use of the current shell with another subshell large parenthesis. For example
$ (var= ' TestVar ';) $ echo $VAR $ {var= ' TestVar ';} $ echo $VAR TestVar
Only the value in the Var inside {} is set. which is used. Be careful not to use it in script.
$ . test.sh arg1 arg2
Because Arg1 Arg2 will continue to call this script's arg1 arg2 to use. The best way is to execute a script that is just a script library without parameters. In addition, if. Test.sh, test.sh leave, call. Test.sh's shell also leaves.
Execute shell script and Subshell.