sed - Getting Day Of Week in bash script -
i want have day of week in variable dow
.
so use following bash-script:
dom=$(date +%d) dow=($($dom % 7) ) | sed 's/^0*//'
but there message bash: 09: command not found
. wished result 2 ( 9 % 7 = 2) in variable $dow
.
how realize this? code works days 1-8 of c-hex there no number on 8 available , message bash: 09: value great base (error token "09")
appears.
you can use -
flag:
dom=$(date +%-d) ^
which prevent day being padded 0
.
from man date
:
- (hyphen) not pad field
observe difference:
$ dom=$(date +%d) $ echo $((dom % 7)) bash: 09: value great base (error token "09") $ dom=$(date +%-d) $ echo $((dom % 7)) 2
Comments
Post a Comment