Current Date and Time
To get current date and time in Bash script, use date command. date command returns current date and time with the current timezone set in the system.
Syntax
The syntax of date command to get current date and time along with timezone set in the system is
date
As simple as that.
Example
In the following script, we take the current date and time in variable dt
, and echo it to the standard console.
Example.sh
</>
Copy
dt=$(date)
echo $dt
Output
Sun Aug 1 11:43:50 IST 2021
Conclusion
In this Bash Tutorial, we have learnt how to get current date and time in Bash Script using date command.