How to print the day before yesterday date in bash shell script

bash print day before yesterday

How to print the day before yesterday in bash?

Printing the day before yesterday date in the UNIX/Linux/Bash shell script is easy, here is the code:

date +%Y%m%d -d "2 days ago"

Here is a Demo, getting the date using a simple shell script.

[[email protected] ~]$ date
Thu Nov  7 02:30:08 EST 2019
[[email protected] ~]$ cat date.sh
#!/bin/bash
# printing day before yesterday date in unix shell script
DAY_BEFORE_YESTERDAY=$(date +%Y%m%d -d "2 days ago")
echo $DAY_BEFORE_YESTERDAY

[[email protected] ~]$ ./date.sh
20191105

Putting it in a shell script

The shell script for your reference:

#!/bin/bash
# printing day before yesterday date in unix shell script
DAY_BEFORE_YESTERDAY=$(date +%Y%m%d -d "2 days ago")
echo $DAY_BEFORE_YESTERDAY