As the track3r solution does, the key here is to convert today's date and day's date of birth in unix timestap. That is, in the number of seconds that have passed since January 1, 1970, which is like the Big Bang unixero.
Therefore, the ideal would be to first normalize the received date, then convert both to unix timestamp, subtract one from the other and finally do the calculation:
#!/bin/bash
read -p "Introduce tu fecha de nacimiento (formato: añomesdia) : " fecha
hoy=$(date)
secs_hasta_fecha=$(date -d"$fecha" "+%s") # esta fecha se da en la hora 00:00:00
secs_hasta_hoy=$(date -d"$hoy" "+%s")
# Calcula la diferencia en segundos entre las dos fechas dadas
dif=$((secs_hasta_hoy - secs_hasta_fecha))
# Calcula la diferencia en horas, minutos y segundos
horas=$((dif / 3600))
mins=$(( (dif - horas*3600) / 60))
segs=$((dif - horas*3600 - mins*60))
# Imprime el resultado
printf "la dif entre %s y hoy %s es de %d horas, %d minutos y %d segundos\n" "$fecha" "$hoy" "$horas" "$mins" "$segs"
Of your code, I can not stop commenting on a couple of things:
!/bin/bash # <--- ¡falta # al principio!
# esto es correcto
read -p "Introduce tu fecha de nacimiento (formato: añomesdia) : " fecha
Probably instead of calculating the date each time, it is better to save it in a variable and then operate from there:
DIAS=$(( ($(date --date $fecha +%s) - $(date +%s) )/(60*60*24) ))
HORAS=$(( ($(date --date $fecha +%s) - $(date +%s) )/(60*60*24) ))
Besides that the variables are always recommended to be in lowercase, so that they do not collide with the environment variables, which by convention are written in uppercase.
echo "Dias: $DIAS"
echo "Horas: $HORAS"
echo "Minutos: $MINUTOS"