📅  最后修改于: 2023-12-03 14:44:34.987000             🧑  作者: Mango
This script is a Shell-Bash program designed to determine Nezuko's age. Nezuko is a character from the anime/manga series "Demon Slayer." The program prompts the user to enter the current year, and based on that information, calculates and displays Nezuko's age.
This script requires the following:
To use this script, perform the following steps:
./nezuko_age.sh
#!/bin/bash
# Prompt for current year
read -p "Enter the current year: " current_year
# Validating user input
re='^[0-9]+$'
if ! [[ $current_year =~ $re ]]; then
echo "Invalid year. Please enter a valid number."
exit 1
fi
# Nezuko's birth year
birth_year=2002
# Calculating Nezuko's age
age=$((current_year - birth_year))
# Displaying Nezuko's age
echo "Nezuko is $age years old."
This script starts by prompting the user to enter the current year. It then validates the input to ensure it is a valid number. Next, it defines Nezuko's birth year as 2002. By subtracting the birth year from the current year, it calculates Nezuko's age. Finally, it displays the result as "Nezuko is <age>
years old."
Enter the current year: 2022
Nezuko is 20 years old.
Please note that this script assumes Nezuko's birth year is fixed at 2002 for simplicity.