Sometimes in our current shell, there is an alias command available, but when we sh script.sh or./script.sh, we find the error alias command not found problem.
What the hell is going on here? Because when you execute a new script with the current shell, the alias of the current shell is not automatically copied to the new shell that executes the script.sh script, so there is no such alias command.
One solution is to use the source command:
SOURCE script.sh
Causes the current shell to read into a file with a path of script.sh and executes all the statements in the file in turn.
So what's the difference between source and SH to execute a script?
The SH script.sh will re-establish a child shell, execute the script inside the child shell, the child shell inherits the environment variable of the parent shell, but the child shell is new and the changed variable will not be brought back to the parent shell unless using export.
Source script.sh is simply reading the script inside the statement in order to execute in the current shell, without creating a new child shell. Then all the new, variable-changing statements in the script will be saved in the current shell.
So what's the difference between SH script.sh and./script.sh?
The same is that they all create a new child shell to execute the script, and the difference is./script.sh requires script.sh to have execute permissions.
An example of a simple alias is:
Alias Ll=ls-l
Original: http://blog.csdn.net/hongchangfirst/article/details/78912188
Author: Hongchangfirst
Hongchangfirst's homepage: http://blog.csdn.net/hongchangfirst