Search code examples
linuxbashexit-code

what's the difference between running a exit command inside a file and a terminal


if I run exit command in terminal, then the terminal will exit and close itself.
if I run the following command then terminal wont close itself (note the use of exit command in if-else command:

#!/bin/bash
a=1
if [ $a -eq 1 ]
then
echo i am true
exit
else
echo i am false
fi

NOTE: I use if-else condition in above code just for demonstration, it has nothing to do with my question.
Please comment if you think there is something wrong with this question, please don't rate it -1.


Solution

  • Executing the script invokes another copy of the script interpreter. It is this interpreter (in this case, bash) that exits, returning control back to the executing program.