Reputation: 569
This bash script in osx does not exit the script. I have changed the settings (as suggested here so that writing exit in terminal closes the window, and I've checked that writing exit does close the terminal window if I write it in the terminal, What could be the reason for this? I restarted terminal and my mac after changing the settings to see if that solved the problem. But exit in at location(s) nr 1 or at the end of the script does not work.
#!/bin/bash
PATH=/opt/local/bin:/opt/local/sbin:$PATH
read -p "What do you want to do?"
if test "$pass" = "f"
then
sh ~/f.sh
exit # nr 1
fi
if test "$pass" = "s"
then
sh ~/s.sh
exit # nr 1
fi
exit # nr 2
Upvotes: 1
Views: 953
Reputation: 80931
Assuming you mean that when you do:
$ exit
your terminal exits.
But when you run
$ ./script.sh
your terminal doesn't exit.
The answer is that your script is being run in its own shell process and so when it exits it isn't exiting from the shell that is running in the terminal.
If you use
$ . script.sh
then you will run the script in the current shell process so exit
will exit the running shell and cause the terminal to exit.
Upvotes: 2