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

</>
Copy
date +%A

The syntax of date command to get current weekday with short name is

</>
Copy
date +%a

Examples

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

</>
Copy
weekday=$(date +%A)
echo "Current Weekday : $weekday"

Output

Current Weekday : Sunday

Current 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

</>
Copy
weekday=$(date +%a)
echo "Current Weekday : $weekday"

Output

Current Weekday : Sun

Conclusion

In this Bash Tutorial, we have learnt how to get current weekday in Bash Script using date command.