so a pretty straight forward question , on zenity theres is 2 buttons on each page , ok and cancel . with my script i manage to assign the zenity code to a variable where i can pick a date for my calendar. I would like to use the cancel button for my agenda , so i renamed it but i don't know how to make it work! thanks
#!/bin/bash
calendarinput=$(zenity --calendar \
--title "Scheduler" \
--text "Pick a date" \
--ok-label "Done" --cancel-label "Agenda" \
--date-format "%A %d/%m/%y")
agenda+="$calendarinput"
unset calendarinput
calendarinput="Done"
if [ "$calendarinput"="Done" ];then remind=$(zenity --entry) agenda+="$remind\n"
fi
zenity --info \
--text "$agenda"This is a only 1 function of my script.There is another list menu before this one.
1 Answer
You can find the return code from the buttons in the special parameter $?, which holds the exit code from the last executed command. It can either be 0, 1, or 5, depending on whether the user pressed OK, Cancel, or timeout.
#!/bin/bash
calendarinput=$(zenity --calendar \
--title "Scheduler" \
--text "Pick a date" \
--ok-label "Done" --cancel-label "Agenda" \
--date-format "%A %d/%m/%y")
ret=$?
if ((ret==0)); then echo "Done"
else echo "Agenda"
fiThe expressions in an if-statement need to be separated with space:
if [ "$calendarinput" = "Done" ]; then(It will also always evaluate as true, which makes it somewhat unnecessary).
1