I have a function which I use in my shell script and based on a certain condition I’d like to call “exit 0” in that function so that the entire script exits. But for some reason the program still runs after calling exit 0 in the function. Why?
check()
{
printf "Would you like to try again?\n"
read S
if [ "$S" = "y" ]
then
./myprog
else
exit 0
fi
}
And I call it like this:
if test $WRONG -eq 7
then
printf "Sorry\n"
check
fi
What you have works for me:
Could you try this test case and update your answer with any differences from it? It appears the problem you’re running into is caused by something you haven’t mentioned.
Update: Example of using a loop instead of calling your program again: