2

Conoce tu edad con un programa en bash

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 )); thenif (( $currentDay >= $birthDay )); thenlet age=$yearsOldecho"$name, you are $age years old"elselet age=$(( yearsOld-1 ))
                echo"$name, you are $age years old"fielselet age=$(( yearsOld-1 ))
        echo"$name, you are $age years old"fi

months=0

if (( $yearsOld==$age )); thenlet months=$(( currentMonth-birthMonth ))
        echo"With $months month(s)"elselet months=$(( 12-birthMonth ))
        let months+=$currentMonthecho"With $months month(s)"fiif (( $currentDay >= $birthDay )); thenecho"With $months month(s)"if (( $currentDay == $birthDay )); thenecho"With 0 days"elseecho"With $(( currentDay-birthDay )) days"fielseecho"With $(( months-1)) month(s)"echo"With $currentDay days"fi
Escribe tu comentario
+ 2