LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   CentOS (https://www.linuxquestions.org/questions/centos-111/)
-   -   shell script - summarise before continuing (https://www.linuxquestions.org/questions/centos-111/shell-script-summarise-before-continuing-4175600416/)

robertkwild 02-23-2017 04:37 AM

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

michaelk 02-23-2017 05:25 AM

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.

hazel 02-23-2017 05:28 AM

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

TenTenths 02-23-2017 06:01 AM

man whiptail

michaelk 02-23-2017 06:20 AM

In addition to zenity and whiptail you can also create graphical boxes with dialog,xdialog or xmessage.

robertkwild 02-23-2017 06:59 AM

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

michaelk 02-23-2017 07:20 AM

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


BW-userx 02-23-2017 09:26 AM

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.


All times are GMT -5. The time now is 08:35 AM.