Pause before exit

 6) printf "\n GoodBye! \n\n"; exit ;; 

I am trying modify the above command to pause a couple of seconds before exiting, so a message can be displayed. Thank you :).

Hi,

Quick way is;

6) printf "\n GoodBye! \n\n"; sleep 2 ; exit ;;

Regards

Dave

It does'nt pause long enough to read the message. Thanks.

Hi,

Increas the sleep in seconds until it does.

Regards

Dave

Hi

You could also put a trap in your script which will catch the EXIT signal (0), and wait for the [enter] key:

trap 'printf "\n GoodBye! \n\n"; read n' 0

or just wait for sleep to time out

trap 'printf "\n GoodBye! \n\n"; sleep 6' 0

Slightly different approach giving a 5 second delay with keyboard override:-

 6) printf "\n GoodBye! \n\n"; read -n1 -s -t5; exit ;;

I'm missing the point of this thread. Exiting a shell script doesn't clear the screen. If you don't want to clear the screen for a few seconds after the script exits, why are you clearing the screen after your script exits???

I'm guessing the OP is using PuTTY or a similar and has the "close window on exit" option enabled.

So why not just turn off the "close window on exit" and manually close the window when the closing message has been read by the user? Even if you add a sleep 600 , it might not be enough if the boss comes in and asks a question just before the job finishes.

If the script is producing output the user needs to see, either the script needs to write it to a log file the user can view later or the output needs to remain on the screen until the user explicitly dismisses it. If the user is using PuTTY and wants to see the message, either redirect the output or turn off the close window on exit option. Rewriting every script that might be invoked by PuTTY with the close on exit option enabled seems like the wrong approach. Should awk , cat , echo , printf , and sed be required to add a 5 second delay before exiting if standard output is connected to a TTY or PTTY device file? I hope we all know the answer to that is NO! So, why should a user written utility be handled differently than a utility defined by the standards?