📜  nezuko 多大了 - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:44:34.987000             🧑  作者: Mango

Title: Nezuko 多大了 - Shell-Bash

Introduction

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.

Requirements

This script requires the following:

  • Bash shell environment
Usage

To use this script, perform the following steps:

  1. Open a terminal.
  2. Navigate to the directory where the script is saved.
  3. Run the script using the command: ./nezuko_age.sh
  4. Follow the prompts and enter the required information.
Script Explanation
#!/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."

Example Output
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.