-1

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
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

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
Hkoof
  • 1,667