0

Convert your days alive to use dialog command and a calendar for date of birth select and current date

Hint:

dialog --stdout --title "Today" --calendar "today" 0 0 0 0 0 | awk -F/ '{ print $2"/"$1"/"$3 }'

Also add You have been alive X years(s) Y days(s) Z hour(s) A minute(s) B second(s) thats what I have but I keep getting errors from reading the date from dialog (Date entered: . ^[[M#<6)

#!/bin/bash
#daysalive
#using hard coded date calc days between two days date 
: ${DIALOG=dialog}

USERDATE=`$DIALOG --stdout --title "CALENDAR" --calendar "Please choose a date..." 0 0` | awk -F/ '{ print $2"/"$1"/"$3 }'

case $? in
  0)
    echo "Date entered: $USERDATE.";;
  1)
    echo "Cancel pressed.";;
  255)
    echo "Box closed.";;
esac


DOBDATE=$($USERDATE \+%S)
NOWDATE=$(date +%s)
echo -n "daysalive"
DAYSALIVE="$(($NOWDATE- $DOBDATE)" / 86400 )
echo $DAYSALIVE
  • You say you're getting errors. What are these errors? – Kusalananda Sep 27 '18 at 7:01
  • Date entered: 27/09/2005. daysalive: line 18: 27/09/2005: No such file or directory daysalivedaysalive: line 21: unexpected EOF while looking for matching `"' daysalive: line 23: syntax error: unexpected end of file – Alaa Ismael Al Sep 27 '18 at 7:02
  • i have seen that post but the problem with reading the date from the dialog – Alaa Ismael Al Sep 27 '18 at 7:36
  • its show me this error now Date entered: . ^[[M#<6 – Alaa Ismael Al Sep 27 '18 at 7:43
0

The general idea of how to calculate number of days between 'now' and a date retrieved from the user by 'dialog' is correct, but the script has a lot of mistakes and errors like unmatched quotes, omitted commands, uppercase S where it should be lowercase s and so on.

Anyway, here's the script with errors fixed:

#!/bin/bash
#daysalive

: ${DIALOG=dialog}

USERDATE=$($DIALOG --stdout --title "CALENDAR" --calendar "Please choose a date..." 0 0 | awk -F/ '{ print $2"/"$1"/"$3 }')

case $? in
  0)
    echo "Date entered: $USERDATE.";;
  1)
    echo "Cancel pressed.";;
  255)
    echo "Box closed.";;
esac


DOBDATE=$(date --date $USERDATE +%s)
NOWDATE=$(date +%s)
echo -n "daysalive"
DAYSALIVE=$(( (NOWDATE - DOBDATE) / 86400 ))
echo $DAYSALIVE
  • thank you for answer i still have to calculate X years(s) Y days(s) Z hour(s) A minute(s) B second(s) but the script working thank you again – Alaa Ismael Al Sep 27 '18 at 15:57
  • thank u guys for your help i am done with it thank you Hkoof for your help – Alaa Ismael Al Sep 28 '18 at 4:23

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