LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 02-23-2017, 04:37 AM   #1
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Rep: Reputation: Disabled
shell script - summarise before continuing


hi all,

wrote a script that asks you multiple questions and before if actually does the commands i want it to give you a quick summary of what you have entered, if its right click continue or if its wrong exit the script and start again?

many thanks,

rob
 
Old 02-23-2017, 05:25 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,694

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
You can create a confirmation yes/no or cancel/yes graphical window box using zenity.

Another option would be to create a default yes/no question so just pressing the Enter key would automatically continue or exit depending on your preference.
 
Old 02-23-2017, 05:28 AM   #3
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,570
Blog Entries: 19

Rep: Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451Reputation: 4451
Hello and welcome to LQ. Please note the thread you started
doesn't meet the minimum threshold that would enable us to help you.
We understand that Linux can be intimidating for new members, and we
really do want to help. That said, please understand that LQ is not a
help desk, customer service line for a product you purchased or
willing to do your homework (although we are happy to assist you with
specifics, if you show some effort of your own!)
. We're a 100%
volunteer organization that wants to help you help yourself.

Here are a couple tips that will enable us to help you moving forward:
  • Before posting, have you used the search function to ensure
    your question hasn't been asked before?
  • If you're actively troubleshooting an
    issue you should also include any steps you've already taken.
If you are unwilling or unable to ask questions in a manner that
allows us to help you, it's unlikely our community will be able to
provide you a solution. Unfortunately, serial offenders who show
wanton disregard for this request after multiple pointers may be asked
to seek help elsewhere. We truly hope that isn't necessary, and assure
you Linux and Open Source are extremely rewarding and well worth the
learning curve in the long run.

Some additional reading that may help:
LQ Search
LQ Sitemap
LQ Site FAQ
How
to ask technical questions to get quality answers
 
1 members found this post helpful.
Old 02-23-2017, 06:01 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
man whiptail
 
Old 02-23-2017, 06:20 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,694

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
In addition to zenity and whiptail you can also create graphical boxes with dialog,xdialog or xmessage.
 
Old 02-23-2017, 06:59 AM   #6
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
echo "is this information correct, press (y) or press (n)"
read correct

case $correct in

y)

echo "the script will now continue";;

n)

echo "please re-run the script inputting correct details"
exit;;

*)

echo "invalid selection, please re-run the script"
exit;;

esac
 
Old 02-23-2017, 07:20 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,694

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
You might want to check for upper case too.
Code:
echo "Is this information correct? (y/n)"
read item
case "$item" in
 y|Y) continue...;;
 n|N) exit";;
 *) exit;;
esac
If you want a default no response.
Code:
read -r -p "Is this information correct? [y/N]" item
case "$item" in
    [yY][eE][sS]|[yY])  
              #if yes,
               echo "Continue"
               ;;
    *)
              #Otherwise exit...
              echo "ciao..."
              exit
              ;;
esac
 
Old 02-23-2017, 09:26 AM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
While Loop

Code:
while [[ not condistion ]] ;
do

1 ask questions
2 spit out summery
3 ask final question before moving on

done

run rest of code here
like this


Code:
while [[ $item != 'y' ]] ; do

read -p 'what is your name? ' name

printf 'this is your name $name\n'

read -p 'is this correct? ' item


done

printf "$name is your correct name.\n"
gui
Code:
while [[ $item != 'y' ]] ; do

read -p 'what is your name? ' name

printf 'this is your name $name\n'

messbox ('is this correct', btn_yes_no);

done

printf "$name is your correct name.\n"
but that is mixing Languages. But the loop remains the same.

Last edited by BW-userx; 02-23-2017 at 10:15 AM.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
Startup scripts not continuing after Shorewall script charleswj Slackware 4 10-11-2005 03:47 PM
Continuing a script on a new subshell dpillay Programming 2 05-29-2004 07:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 11:15 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