Get Day Of Week in bash script
Solution 1:
Use %u
. Like this:
DOW=$(date +%u)
From the man page:
%u day of week (1..7); 1 is Monday
Solution 2:
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
Solution 3:
This works fine here
#!/bin/sh
DOW=$(date +"%a")
echo $DOW