0

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?

artu-hnrq
  • 1,343
  • 1
  • 8
  • 30
  • 1
    Run your script with `exec`? See: `help exec` – Cyrus Apr 24 '20 at 03:33
  • 1
    @artu-hnrq : Since you don't know how deep down in the process hierarchy your script runs (it might have been called by another script, and this in turn by yet another script), you have to look down the process hierarchy until you find a process with the name of your terminal process. – user1934428 Apr 24 '20 at 06:23

0 Answers0