I have one bash source run.sh
as follows,
#!/bin/bash
if [ $# -ne 1 ]; then
exit
fi
...
when I execute it in two ways, there are different behaviors. The first way is,
source run.sh
It will close the terminal after execution. The second way is,
./run.sh
this will simply finish running the script, and stay on the terminal. I am asking if there is a command for exiting a bash scripts for both source run.sh
and ./run.sh
execution. I have tried return
too, which does not work well under ./run.sh
execution.
More generally, I am interested in why this is happening, and what's difference between using "source" and "." for script execution?