Write a linux shell program to perform find age of a person using set date
Find age of a person using set date
Code:
TODAY=$(date +"%Y-%m-%d")echo "May I know your name"
read name
echo "Your birthdate(yyyy-mm-dd)"
read birthdate
tmpDays=$( printf '%s' $(( $(date -u -d"$TODAY" +%s) - $(date -u -d"$birthdate" +%s))) )
age=$(( $tmpDays / 60 / 60 / 24 / 364 ))
echo Hai $name you are $age years old.
Output:
May I know your nameSatheesh
Your birthdate(yyyy-mm-dd)
1989-12-08
Hai Satheesh you are 24 years old.
Leave a Comment