LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-02-2008, 10:50 AM   #1
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Rep: Reputation: 39
Setting Up an Interactive Section within a Shell Script


Hi there --

I want to add an interactive section within a shell script where a pause will occur to allow the user to either hit the 'y' key to continue onto the next section, or the 'n' key to stop and exit from the script. The code that has been written thus far is shown below

Code:
#!/bin/bash

# This script will activate the local e-mail client for the
# user in order to facilitate the transfer of any screengrab
# to an e-mail account and/or PC.

# Display the following message on-screen prior to starting
# the e-mail application.

echo
echo
echo    ----------------------------------------------------
echo    Screengrab transfer utility 
echo    ----------------------------------------------------
echo
echo 	If there are any questions or concerns,
echo 	please contact the system administrator.
echo
echo
echo
echo    Press any key to continue...
Can someone provide me with the correct syntax to complete this task? Thanks.
 
Old 09-02-2008, 11:32 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,325

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
I would do it this way:
Code:
old=$(stty -g)
stty -icanon

echo -n "Continue? [y/n]: "
while a=$(head -c1); do
    case $a in
        y)
          echo
          break;
          ;;
        n) 
          echo 
          echo "Canceled by user"
          exit
          ;;
        *)
          echo
          echo "Please hit only y or n key"
          echo -n "Continue? [y/n]: "
          ;;
    esac
done
stty $old
echo "Ok, next section..."

Last edited by keefaz; 09-02-2008 at 11:34 AM. Reason: code formating...
 
Old 09-02-2008, 12:29 PM   #3
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Original Poster
Rep: Reputation: 39
Hi there --

Thanks for your reply. I implemented your suggestion, and it worked great.

Much obliged to you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH - How to open an interactive script from a non interactive script..... OldGaf Programming 4 06-29-2008 04:34 PM
shell script in non interactive way googlix Linux - General 6 11-13-2007 09:18 AM
script connecting to erlang shell works only in interactive mode ineya Linux - Server 1 10-25-2007 07:05 AM
shell script read non-interactive comtmr Linux - General 6 11-01-2006 06:54 AM
interactive and non-interactive shell linuxjamil Programming 3 09-03-2006 08:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration