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
  • 575

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
  • 9,643
  • Hi @choroba Thank you for explaining. Instead of cutting short the sequence with "CTRL+C" could I simply have entered the second inverted commas manually and would my command then have been executed? – Rosika Feb 10 '21 at 15:51
  • And what happened when you tried it? You can type " )) )) and press Enter again, so the shell can throw the syntax error. – choroba Feb 10 '21 at 16:14
  • Hi. Following up your suggestion and typing " )) )) after entering the faulty command I get the following: date: invalid date ‘2018-01-08)-946335600)/(3600*24))) days\n’ bash: () : syntax error: operand expected (error token is ") ") – Rosika Feb 10 '21 at 16:28
  • Yes, that's exactly what I've shown in the answer. – choroba Feb 10 '21 at 17:12
  • Thanks for your help. I think everything´s clear now. Many greetings. – Rosika Feb 11 '21 at 15:25
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,696