Linux / Unix Shell Script Get Current Year

In a Linux or Unix shell script, you can get the current year using the date command. For example:

current_year=$(date +%Y)

The date command is used to print or set the system date and time, and the +%Y option specifies that the year in the format YYYY should be displayed. The output of the date command is stored in the variable current_year.

You can then use the value of current_year in your script as needed. For example, you could use it to log the current year:

echo "The current year is: $current_year"

Leave a Comment