Current Weekday
To get current weekday in Bash script, use date command with the format that outputs only weekday.
There are two different types of format in which we could get weekday from the date. They are
- Full name of weekday (Ex: Sunday, Monday, etc.)
- Short name of weekday (Ex: Sun, Mon, etc.)
In this tutorial, we will learn the syntax to get the current weekday in the above said formats, with examples.
Syntax
The syntax of date command to get current weekday with full name is
date +%AThe syntax of date command to get current weekday with short name is
date +%aExamples
Current Weekday – Full Name
In the following script, we get current weekday using date command in full name format, and print it to standard console.
Example.sh
weekday=$(date +%A)
echo "Current Weekday : $weekday"Output
Current Weekday : SundayCurrent Weekday – Full Name
In the following script, we get current weekday using date command in short name format, and print it to standard console.
Example.sh
weekday=$(date +%a)
echo "Current Weekday : $weekday"Output
Current Weekday : SunConclusion
In this Bash Tutorial, we have learnt how to get current weekday in Bash Script using date command.
