First, use '. ' Perform1. Contents of the file:
a.sh
#!/bin/sha=2echo a= $a
b.sh
#!/bin/sh./a.shecho a.sh:a= $a
2. Add executable permissions
# chmod +x a.sh b.sh
3. Running
#./b.sh a=2a.sh:a=
It can be seen that a in b.sh does not get the A variable in a.sh, it just executes the a.sh once.
second, using Source to execute
1. Contents of the file:
a.sh
#!/bin/sha=2echo a= $a
b.sh
#!/bin/shsource./a.shecho a.sh:a= $a
2. Add executable permissions
# chmod +x a.sh b.sh
3. Running
#./b.sh a=2a.sh:a=2
A variable in a.sh is obtained in the visible b.sh
Iii. Conclusion
In fact, '. ' Just executes the shell script once, and source is adding code from the shell script to the current script, similar to the Include in C.
We'll use Bash-x to see the details.
1) '. ' The way
# sh-x b.sh +./a.sha=2+ echo a.sh:a=a.sh:a=
2) Source of the way
# sh-x b.sh + source./a.sh++ a=2++ echo a=2a=2+ Echo a.sh:a=2a.sh:a=2
Can see '. ' The way only executes the a.sh and outputs the results of a.sh a=2; The source method is to add the a.sh code to the b.sh and then execute.
The difference between a Linux shell source and a.