0

recently I wanted to calculate the time difference of two dates (in days) using a one-liner in bash. So I wanted to use the command

echo $((($(date +%s --date "2018-01-08")-$(date +%s --date "1999-12-28"))/(3600*24))) days

which would yield "6586 days".

Out of clumsiness I forgot to type the finishing inverted commas in the first date entry:[ date +%s --date "2018-01-08 ]

I got this output:

echo $((($(date +%s --date "2018-01-08)-$(date +%s --date "1999-12-28"))/(3600*24))) days
bash: command substitution: Zeile 4: Dateiende beim Suchen nach »"« erreicht.
bash: command substitution: Zeile 5: Syntaxfehler: Unerwartetes Dateiende.
> ^C
rosika@rosika-10159:~$ echo $?
130

The error messages are clear I think but I didn´t get my command prompt back. The system seems to have been waiting for something. Yet it´s not clear me for what.

I finally entered "CTRL+C" and so I got my command prompt back. I hope I did the right thing there.

The error code was "130". Well, it´s clear to me that it couldn´t be "0".

What I´d like to understand is: what is it that the system could have been waiting for?

Perhaps some of you knowledgeable folks could shed some light on the matter?

Thanks a lot in advance.

Many greetings. Rosika

P.S.:

my system: Linux/Lubuntu 20.04.2 LTS, 64 bit

Rosika
  • 585

2 Answers2

0

The shell was waiting for the closing double quote and twice the closing )).

$ echo $((($(date +%s --date "2018-01-08)-$(date +%s --date "1999-12-28"))/(3600*24))) days" )) ))
date: invalid date ‘2018-01-08)-946335600)/(3600*24))) days’
bash: () : syntax error: operand expected (error token is ") ")
$ echo $?
1
choroba
  • 10,313
0

Your command contains a syntax error : missing double quote at second date call :

--date "2018-01-08

user@host:~$ echo $((($(date +%s --date "2018-01-08")-$(date +%s --date "1999-12-28"))/(3600*24))) days
6586 days
cmak.fr
  • 8,976