What is the difference between the source filename and the sh filename and./filename execution script?
1. When the shell script has executable permissions, there is no difference between using SH filename and./filename to execute the script:/filename because the current directory is not in path, all "." is used to represent the current directory.
2.sh filename re-establishes a child shell, executes the statement inside the script in the child shell, which inherits the environment variables of the parent shell, but the new, changed variables of the child shell are not brought back to the parent shell unless export is used.
3.source FileName: This command actually simply reads the statements inside the script and executes them sequentially in the current shell, without creating a new child shell. Then all the new and changed statements in the script will be stored in the current shell.
To illustrate:
1. Create a new test.sh script with the content: A=1
2. Then make it executable chmod +x test.sh
3. After running SH test.sh, the Echo $A appears empty because A=1 is not passed back to the current shell
4. Run. After/test.sh, it is the same effect
5. Run source test.sh or. Test.sh, and then Echo $A, it will show 1, indicating that the a=1 variable is in the current shell
Linux Source command