bash - How to use DATE command with an external variable? -
i'm working on time convertion script. supposed this:
echo $(( ($(date -d '00:10:2.00' +%s) - $(date -d 0 +%s) ) ))
this line working fine giving me result
602
but want put the first part of date string (00:10:2.00
) under a) command line argument read $1
like:
echo $(( ($(date -d '$1' +%s) - $(date -d 0 +%s) ) ))
or variable:
echo $(( ($(date -d '$myvariable' +%s) - $(date -d 0 +%s) ) ))
when i'm trying this:
foo="00:10:2.00" echo $foo echo $(( ($(date -d '$foo' +%s) - $(date -d 0 +%s) ) ))
all is:
00:10:2.00 date: invalid date `$foo' -1417042800
so it's echoing aint working time command...
variables expanded inside double quotes, they're not expanded inside single quotes. use
date -d "$1" +%s
Comments
Post a Comment