Following this answer, I included the follow function in my .bashrc
to allow my scripts to check if user wants to quit actual session, closing the terminal
close(){
[[ $1 =~ ^-[yY]([eE][sS])?$ ]] && exit 0 || write -r "Should it close? [Y/n]"
while true; do
read -p "" answer
case $answer in
[Yy] ) exit 0;;
[Nn] ) break;;
* ) [[ $answer == "" ]] && exit 0 || write -y "Please answer (Y)es or (n)o.";;
esac
done
}
It works, closing terminal window, when I direct run the command in my session, however it doesn't when it is called from within a script I run.
The exit 0
call is only concluding the script, instead of close terminal window as I desire.
How could I achieve this behavior?