I'm using a CentOS and I want to write a shell script. So
I have a file with a date:
>
> cat VM1_EOMAP_TIME.log
07 Sep 2022 16:30
>
And I want to get the minutes since current time and the date in the file
My idea is: ("EPOCH from current time" - "EPOCH from the date of that file") / 60
But I can't get the "EPOCH from current time"
> cat VM1_EOMAP_TIME.log
07 Sep 2022 16:30
> date --date='07 Sep 2022 16:30' +%s
1662568200
> date --date=$(cat VM1_EOMAP_TIME.log) +%s
date: extra operand ‘2022’
Try 'date --help' for more information.
> date --date=cat VM1_EOMAP_TIME.log
+%s
date: extra operand ‘2022’
Try 'date --help' for more information.
> TTT="07 Sep 2022 16:30"
> echo $TTT
07 Sep 2022 16:30
> date --date=$TTT +%s
date: extra operand ‘2022’
Try 'date --help' for more information.
Why I get "date: extra operand ‘2022’" error?
--date=$TTT
expands to--date=07 Sep ...
so you have extra arguments. Try--date="$TTT"
. – doneal24 Sep 07 '22 at 16:55