First file (trigger.sh):
#!/usr/bin/env bash
echo "Configuring tests"
echo "Source 1"
source ./run-1.sh -m "George"
echo "Source 2"
source ./run-1.sh -m "Fred"
echo "End"
Second file (run-1.sh):
#!/usr/bin/env bash
echo "IN run-1"
while getopts m: flag; do
case "${flag}" in
m) MODE=${OPTARG} ;;
esac
done
echo "before mode"
echo "$MODE"
echo "after mode"
Output:
./trigger.sh
Configuring tests
Source 1
IN run-1
before mode
George
after mode
Source 2
IN run-1
before mode
George
after mode
End
If you look at the Output when trigger.sh is executed, you will see the second source call does not update the argument to “Fred” but it keeps it as “George”.
What’s the reason for this? Any workaround using source
?