0

I am having issue getting a dialog box to display time. I am using date +"%T" as the means to show the time but when I use it in a message dialog it just shows it verbose as date +"%T" rather then 07:41:40 I have tried assigning the value to a variable and calling it in the dialog box script but still I can not get it to work. I am wondering if my response dialog box needs to be a different format or if my parentheses usage is screwy. This is what I have so far.

#!/bin/bash

dialog --title "Message"  --yesno "Do you want to see the system time?" 6 25

z="date +"%T""
if [ "$?" != "1" ]
then
  dialog --title "message"  --msgbox "$z" 6 25
else
  dialog --title "Message"  --msgbox "ok soo what" 6 25 
fi
chepner
  • 497,756
  • 71
  • 530
  • 681
Grunt
  • 47
  • 1
  • 6
  • 1
    I suggest to replace `z="date +"%T""` by `z=$(date +"%T")`. – Cyrus May 20 '17 at 13:02
  • Ok I got that part fixed and I can now get the date as a response but it seems no matter which selection is made I get the date. In a yesno dialog box yes is supposed to give you a "0" and no is supposed to give you a "1" but I does not seem what I hit in the box the outcome is the same. – Grunt May 20 '17 at 15:27

1 Answers1

1

I suggest:

#!/bin/bash

dialog --title "Message"  --yesno "Do you want to see the system time?" 6 25

if [ "$?" != "1" ]
then
  z=$(date +"%T")
  dialog --title "message" --msgbox "$z" 6 25
else
  dialog --title "Message" --msgbox "ok soo what" 6 25 
fi

$? contains the return code of the previous command.

Cyrus
  • 84,225
  • 14
  • 89
  • 153