Exec also allows the script to be executed in the same process, but the original process is ended.
Script content:
Root @ James-desktop:/opt/Qt-everywhere/Marvell/APP/applications/factory-Roast # Cat 1.sh
#! /Bin/sh
A = B
Echo "PID for 1.sh: $"
Export
Echo "1.sh \ $ A is $"
Case $1 in
Exec)
Echo "using exec ..."
Exec./2.sh ;;
Source)
Echo "using source ..."
Source./2.sh ;;
*)
Echo "using fork ..."
./2.sh ;;
Esac
Echo "PID for 1.sh after run 2.sh:$ $"
Echo "1.sh \ $ A is $"
Root @ James-desktop:/opt/Qt-everywhere/Marvell/APP/applications/factory-Roast # Cat 2.sh
#! /Bin/sh
Echo "PID for 2.sh: $"
Echo "2.sh get \ $ A = $ A from 1.sh"
A = C
Export
Echo "2.sh \ $ A is $"
Running result:
Root @ James-desktop:/opt/Qt-everywhere/Marvell/APP/applications/factory-Roast #./1.sh
PID for 1.sh: 8152
1. Sh $ A is B
Using fork...
PID for 2.sh: 8153
2. Sh get $ A = B from 1.sh
2. Sh $ A is C
PID for 1.sh after run 2.sh: 8152
1. Sh $ A is B
Root @ James-desktop:/opt/Qt-everywhere/Marvell/APP/applications/factory-Roast #./1.sh Source
PID for 1.sh: 8158
1. Sh $ A is B
Using source...
PID for 2.sh: 8158
2. Sh get $ A = B from 1.sh
2. Sh $ A is C
PID for 1.sh after run 2.sh: 8158
1. Sh $ A is C
Root @ James-desktop:/opt/Qt-everywhere/Marvell/APP/applications/factory-Roast #./1.sh Exec
PID for 1.sh: 8159
1. Sh $ A is B
Using exec...
PID for 2.sh: 8159
2. Sh get $ A = B from 1.sh
2. Sh $ A is C