I'm trying to work out the difference in 2 unix times to do a simple calculation (in a shell script) but it doesn't seem to work.
I have set 2 variables one called $d
and the other $c
.
Here's the syntax i currently have for setting up the variables:
c= echo $a | awk -F : '{print ($1 * 32140800) + ($2 * 2678400) + ($3 * 86400) + ($4 * 3600) + ($5 * 60) }'
echo $c
d= echo $a | awk -F : '{print ($1 * 32140800) + ($2 * 2678400) + ($3 * 86400) + ($4 * 3600) + ($5 * 60) }'
echo $d
(variables a and b simply receive the timestamp from another script)
I'm trying to subtract the output of $c
from $d
but every method I have used doesn't seem to work.
I've tried the following: 1)
duration=$(echo "$d - $c")
echo $duration
2)
duration=$((d-c))
echo $duration
c= echo
, orc=foo echo
, it only setsc
for the duration of theecho
. The assignment is only permanent if there's no actuall command to run on the same command line. Here, it doesn't show, an undefined variable acts pretty much the same as one assigned an empty string. – ilkkachu Nov 07 '19 at 16:31