2

I'm using YAD to create a Yes or No dialog box in a bash script:

yad --image "dialog-question" --title "Alert" --button=gtk-yes:0 --button=gtk-no:1 --text "Are you sure you want to do this?"

If I click "No" to the question I want the bash script to terminate. If I click "Yes" I want the rest of the operations in the bash script to execute.

What code should I add to accomplish this?

2

Here a full working example :

if yad \
    --image "dialog-question" \
    --title "Alert" \
    --button=gtk-yes:0 \
    --button=gtk-no:1 \
    --text "Are you sure you want to do this?"
then
    do_the_rest...
    ...
    ...
else
    exit 1
fi
  • Do I replace "do the rest" with the others commands I want to execute were I to click "Yes"? – user8547 Nov 12 '14 at 18:02
  • Duh, sure user8547 ! – Gilles Quenot Nov 12 '14 at 18:03
  • I tested it and it worked. – user8547 Nov 12 '14 at 18:07
  • Are you surprised ? =) – Gilles Quenot Nov 12 '14 at 18:08
  • I'm too busy being sexy to be surprised. – user8547 Nov 12 '14 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.