En este programa tu vas a insertar tu nombre, año, mes y día de nacimiento, para que de esta manera te diga cuantos años tienes y cuantos meses. Aquí esta el código:
#!/bin/bash
currentYear=$(date +%Y)
currentMonth=$(date +%m)
currentDay=$(date +%d)
echo "What is your name?"
read name
echo "What is the year of your birth?"
read birthYear
echo "What is the month of your birth?"
read birthMonth
echo "What is the day of your birth?"
read birthDay
yearsOld=$((currentYear-birthYear))
age=0
if (( $currentMonth >= $birthMonth )); then
if (( $currentDay >= $birthDay )); then
let age=$yearsOld
echo "$name, you are $age years old"
else
let age=$(( yearsOld-1 ))
echo "$name, you are $age years old"
fi
else
let age=$(( yearsOld-1 ))
echo "$name, you are $age years old"
fi
months=0
if (( $yearsOld==$age )); then
let months=$(( currentMonth-birthMonth ))
echo "With $months month(s)"
else
let months=$(( 12-birthMonth ))
let months+=$currentMonth
echo "With $months month(s)"
fi
if (( $currentDay >= $birthDay )); then
echo "With $months month(s)"
if (( $currentDay == $birthDay )); then
echo "With 0 days"
else
echo "With $(( currentDay-birthDay )) days"
fi
else
echo "With $(( months-1)) month(s)"
echo "With $currentDay days"
fi
Curso de Programación en Bash Shell
0 Comentarios
para escribir tu comentario