Home > Shell Scripting > Implementing Yes/No to continue

Implementing Yes/No to continue

Here is a quick how-to for doing something like “Do you wish to continue Yes/No” within shell scripting:

 echo "Will you like to delete $dir under $PWD for a fresh extract? (y/n)"
 read opt
        case $opt in
                Y|y) cleanfolder $dir ;;
                [Yy][Ee][Ss]) cleanfolder $dir ;;
                N|n) exit ;;
                [Nn][Oo]) exit ;;
                *) exit;;

This will look for almost all kinds of combination of Yes/No options and do the appropriate action depending on the user input.

Shoaib Mir

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s