I am pretty unexperienced (to put it mildly) when it comes to BASH and Shell scripting, so bear with me:
$ toda=$(date) | echo $toda
gives me: Fr 29 Mai 2020 15:25:19 CEST. So far so good.
datediff is part of the dateutils package and gives back the number of days between to dates:
datediff 2019-12-31 2020-05-29
gives me: 150. Again, so far so good. But:
toda=$(datediff 2019-12-31 2020-05-29) | echo $toda
gives me back: Fr 29 Mai 2020 15:25:19 CEST and not (as expected) 150. In other words it did not assign the datediff result but kept the value from the former operation unchanged. Of course I tried:
anothervarname=$(datediff 2019-12-31 2020-05-29) | echo $anothervarname
which gives back an empty variable (ie a blank line above the prompt). What do I have to do to assign the datediff result from the above example to a variable? Thanks for your help.
unset toda; toda=$(date) | echo $toda
. – fra-san May 29 '20 at 15:09