`Why can't I perform arithmetic on a variable received via curl?
O
O
Olga Moskvitina2017-08-26 20:00:39
linux
Olga Moskvitina, 2017-08-26 20:00:39

Why can't I perform arithmetic on a variable received via curl?

For example:

#!/bin/bash

last_time_online=`curl -s "http://lolygirl.ru/time_online.php?client=clear"`
curr_date=`date +%s`
echo $(($curr_date - $last_time_online))

line 4: 1503766814 - 1503766801: syntax error: operand expected (erroneous label "1503766801")
Although if you take the curl output with handles and drive it in as a string, then everything works fine

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xibir, 2017-08-26
@loly_girl

in last_time_online after the last digit there is one more character, it must be cut off

last_time_online=`curl -s "http://lolygirl.ru/time_online.php?client=clear"`
last_time_online=${last_time_online:1:${#last_time_online}-1}
curr_date=`date +%s`
echo $(($curr_date - $last_time_online))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question