Skip to content

Instantly share code, notes, and snippets.

@tanzyy
Last active March 28, 2017 22:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tanzyy/c3c1161a6fb38025fa06f1203574377a to your computer and use it in GitHub Desktop.
Loop with date (MAC)
#!/bin/bash
# On MAC date -d option does not work rather -v.
# Below code logic is as follows:
# Create folders with date(in format YYYY-MM-DD) with consecutive dates until it reaches to input difference
# Here variable datediff is 28 meaning from current date, it will generate dates until there is difference of 28.
now=$(date -v -1d +"%Y-%m-%d")
datediff=28
for (( c=0; c<=$datediff; c++ ))
do
echo $c;
now=(`date -v -"$c"d +"%Y-%m-%d"`);
mkdir /tmp/"$now"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment