Get Day Of Week in bash script
Using a different %-specifier is the real answer to your question. The way to prevent bash from choking on invalid octal numbers is to tell it that you actually have a base-10 number:
$ DOM=09
$ echo $(( DOM % 7 ))
bash: 09: value too great for base (error token is "09")
$ echo $(( 10#$DOM % 7 ))
2
This works fine here
#!/bin/sh
DOW=$(date +"%a")
echo $DOW
You can also use to return the day name
date +'%A'
Use %u
. Like this:
DOW=$(date +%u)
From the man page:
%u day of week (1..7); 1 is Monday