This question is related to the thread here:
Today's date, minus X days in shell script
But because I’m now manipulating the variable, I started another thread.
As described above, I need to get today’s date minus 200 days, with the Year, Month, and Day in separate variables (in this question I’ll use 200, though in the other it’s 222). However, I need to represent January as 0, February as 1 (or 01), March as 2 (or 02), etc… I tried this:
MONTHS200=$(date -j -v-200d -v-1m +"%m")
if ${MONTHS200}=01; then
${MONTH200}=0
else ${MONTHS200}=${MONTH200}
fi
But I get the error ./update_newdateformat.sh: line 20: 12=01: command not found ./update_newdateformat.sh: line 23: 12=: command not found The -v-1m works for all months except January, because it goes to 12, instead of 0
Here’s how to shift all the month number down by 1 n your script:
Here is how to use
ifand=(assignment) syntax in shell:Note that for numerical comparisons, you need to use:
-eqinstead of==-neinstead of!=-ltinstead of<-leinstead of<=-gtinstead of>-geinstead of>=For example: