Multiplication error in shell script
I coded this shell script
#!/bin/bash
VAR1=`awk -F"#" '/futuro/ { print $1 }' config.conf`
HOST="www.odds.com/matches/soccer/"
ONEDAY=86400
TODAYN=`date +%s`
VAR2= expr $VAR1 \\* $ONEDAY
TODAY=`date -d @$(($TODAYN + $VAR2)) +%Y%m%d`
TOMORROW=`date -d @$(($TODAYN + $ONEDAY)) +%Y%m%d`
FULLTODAY=$HOST$TODAY"/"
FULLTOMORROW=$HOST$TOMORROW"/"
... some other stuff
开发者_Go百科but when I try to execute it, I get this error
riga 8: 1314967172 + : errore di sintassi: atteso un operando (il token di errore è "+ ")
where is the error?
Change
VAR2= expr $VAR1 \\* $ONEDAY
to
VAR2=$(( VAR1 * ONEDAY ))
But, you should be able to say this instead:
HOST="www.oddsportal.com/matches/soccer/"
DAYS=$(awk -F"#" '/futuro/ { print $1 }' config.conf)
TODAY=$(date -d "$DAYS days" +%Y%m%d)
FULLTODAY="${HOST}${TODAY}/"
FULLTOMORROW="${HOST}$(date -d "$TODAY + 1 day" +%Y%m%d)/"
VAR2
is not correctly initialized: its value is ""
. Maybe you forgot backticks.
But you should replace backticks by $( ... )
construct.
Moreover, expr
is not the best way to do a multiplication here. Why not use $(( ... ))
that you already use with additions?
精彩评论