Date arithmetic formating in Bash I have a script that creates previous week's folders with the week number in the name. Here's how I'm getting the value of the current week number and assigning the previous week's number.

WEEKNBR=$(date +"%V")
PREVWK=$((WEEKNBR-1))


The value of WEEKNBR is in a two digit form eg. "Week05" but the PREVWK would be "WEEK4".
How would  go about subtracting 1 from WEEKNBR and have the result be preceded by 0 when applicable?
You can use date to do the arithmetic for you. With BSD date:

$ /bin/date +%V
03
$ /bin/date -v-1w +%V
02


From man date:

-v   Adjust (i.e., take the current date and display the result of the
     adjustment; not actually set the date) the second, minute, hour,
     month day, week day, month or year according to val.  If val is
     preceded with a plus or minus sign, the date is adjusted forwards
     or backwards according to the remaining string, otherwise the
     relevant part of the date is set.  The date can be adjusted as
     many times as required using these flags.  Flags are processed in
     the order given.


In case you have installed and are using GNU date:

$ date -d '-1week' +%V
02
$ date -d '-1 week' +%V
02
$ date -d 'now - 1 week' +%V
02
$ date -d 'last week' +%V
02