Little Girl's Mostly Linux Blog

PauseBashScript

Pause a Bash script

This page was last updated on July 20, 2009.

Use this in your script to add a pause by asking for user input:
#!/bin/bash

#############################################
# GET MY ATTENTION WITH A BEEP:             #
#############################################
echo $'\a'
#############################################
# ASK ME IF I WANT TO CONTINUE:             #
#############################################
echo -n "Continue running the script? (y/n) "
#############################################
# CHECK OUT MY REPLY:                       #
#############################################
read -n1 reply
echo
#############################################
# ACT ON MY REPLY:                          #
#############################################
if [ $reply = "y" -o $reply = "Y" ]; then
   echo "Continuing!"
elif [ $reply = "n" -o $reply = "N" ]; then
   exit 1
fi

See also Howto: Pause a Shell Script by Chris Collins.


Obligatory Happy Ending

And they all lived happily ever after. The end.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: