Lu1 (){
Echo 'aaaaaaaaa'
}
Lu2 (){
Echo 'bbbbbbbbbbbb'
}
The above is the source code of run. Sh. We can see that there are only two function definitions and there is no place to call these two functions. If we execute these two functions like this:
Luther @ gliethttp :~ $./Run. Sh
Luther @ gliethttp :~ $
We can see that there is nothing, because there is no place to call these two functions. We hope that in our Luther @ gliethttp :~ $ Call these two functions at the end of the prompt to try,
Luther @ gliethttp :~ $ Lu1
Bash: lu1: Command not found
Luther @ gliethttp :~ $ Lu2
Bash: lu2: Command not found
Luther @ gliethttp :~ $
The results all showed that the command could not be found. Isn't shell our requirement not yet supported? Of course not. Such a useful requirement shell has already prepared a solution for us to see how to implement it,
There are two commands in shell to complete our work. One is source and the other is the. Comma operator equivalent to source:
Luther @ gliethttp :~ $. Run. Sh or Luther @ gliethttp :~ $ Source run. Sh
In this case, run. the variables and functions created in the sh script are added to the execution. or source shell, until the shell window is closed, otherwise run. the variables and functions created in SH will always be valid,
If we only execute. /run. sh starts a subshell to run our run. sh script, then run. the variables and functions in the sh script will closely affect the subshell started by the shell. /run. run. the life of SH variables and functions has reached the end.
Let's take a look at the current phenomenon:
Luther @ gliethttp :~ $./Run. Sh
Luther @ gliethttp :~ $ Lu1
Bash: lu1: Command not found
Luther @ gliethttp :~ $ Lu2
Bash: lu2: Command not found
Luther @ gliethttp :~ $. Run. Sh
Luther @ gliethttp :~ $ Lu1
Aaaaaaaaa
Luther @ gliethttp :~ $ Lu2
Bbbbbbbbb
Luther @ gliethttp :~ $
Restart a new shell:
Luther @ gliethttp :~ $./Run. Sh
Luther @ gliethttp :~ $ Lu1
Bash: lu1: Command not found
Luther @ gliethttp :~ $ Lu2
Bash: lu2: Command not found
Luther @ gliethttp :~ $ Source run. Sh
Luther @ gliethttp :~ $ Lu1
Aaaaaaaaa
Luther @ gliethttp :~ $ Lu2
Bbbbbbbbb
Luther @ gliethttp :~ $