A=999 echo "before fork: PID for file1.sh = $$" export A echo "In file1.sh: variable file1_variable=$A"
echo -e "==>>> using fork start\n" /home/hk/1sharedfiles/6temp/file2.sh
echo "after exec/source/fork: PID for file1.sh = $$" echo -e "In file1.sh: variable file1_variable=$A\n"
被调shell脚本:file2.sh
1 2 3 4 5 6 7 8
#!/bin/bash # filename: file2.sh
echo "PID for file2.sh = $$" echo "In for file2.sh get variable file1_variable=$A from file1.sh" A=111 export A echo -e "In for file2_variable.sh: variable for file2_variable=$A\n"
执行结果如下
1 2 3 4 5 6 7 8 9 10 11
hk@ubuntu-22-04:~/1sharedfiles/6temp$ ./file1.sh before fork: PID for file1.sh = 6773 In file1.sh: variable file1_variable=999 ==>>> using fork start
PID for file2.sh = 6774 In for file2.sh get variable file1_variable=999 from file1.sh In for file2_variable.sh: variable for file2_variable=111
after exec/source/fork: PID for file1.sh = 6773 In file1.sh: variable file1_variable=999
A=999 echo "before fork: PID for file1.sh = $$" export A echo "In file1.sh: variable file1_variable=$A"
echo -e "==>>> using fork start\n" exec /home/hk/1sharedfiles/6temp/file2.sh
echo "after exec/source/fork: PID for file1.sh = $$" echo -e "In file1.sh: variable file1_variable=$A\n"
被调shell脚本:file2.sh
1 2 3 4 5 6 7 8
#!/bin/bash # filename: file2.sh
echo "PID for file2.sh = $$" echo "In for file2.sh get variable file1_variable=$A from file1.sh" A=111 export A echo -e "In for file2_variable.sh: variable for file2_variable=$A\n"
执行结果如下
1 2 3 4 5 6 7 8
hk@ubuntu-22-04:~/1sharedfiles/6temp$ ./file1.sh before fork: PID for file1.sh = 6808 In file1.sh: variable file1_variable=999 ==>>> using fork start
PID for file2.sh = 6808 In for file2.sh get variable file1_variable=999 from file1.sh In for file2_variable.sh: variable for file2_variable=111
A=999 echo "before fork: PID for file1.sh = $$" export A echo "In file1.sh: variable file1_variable=$A"
echo -e "==>>> using fork start\n" . /home/hk/1sharedfiles/6temp/file2.sh
echo "after exec/source/fork: PID for file1.sh = $$" echo -e "In file1.sh: variable file1_variable=$A\n"
被调shell脚本:file2.sh
1 2 3 4 5 6 7 8
#!/bin/bash # filename: file2.sh
echo "PID for file2.sh = $$" echo "In for file2.sh get variable file1_variable=$A from file1.sh" A=111 export A echo -e "In for file2_variable.sh: variable for file2_variable=$A\n"
执行结果如下
1 2 3 4 5 6 7 8 9 10 11
hk@ubuntu-22-04:~/1sharedfiles/6temp$ ./file1.sh before fork: PID for file1.sh = 6840 In file1.sh: variable file1_variable=999 ==>>> using fork start
PID for file2.sh = 6840 In for file2.sh get variable file1_variable=999 from file1.sh In for file2_variable.sh: variable for file2_variable=111
after exec/source/fork: PID for file1.sh = 6840 In file1.sh: variable file1_variable=111