I know there have been a lot of similar questions here but this is pretty special, please read on.
I have a bash script that does nothing but comparing two numbers, basically like that:
[[ 1408039118 -lt 1401215749 ]]
Now, running that script throws the following error:
/usr/bin/pacaur: line 179: 1408039118: syntax error: invalid arithmetic operator (error token is "")
So I understand something must be wrong, this is my line 179:
[[ "${depsAlastmodified[$i]}" -lt 1401215749 ]] && note "f" $"no AUR metadata for ${colorR}${depsAname[$i]}${reset} package"
Running this through bash -x shows:
+ [[ 1408039118 -lt 1401215749 ]]
/usr/bin/pacaur: line 179: 1406628774: syntax error: invalid arithmetic operator (error token is "")
There is really nothing visible wrong with that. I tried some further debugging using od -c on that variable:
echo ${depsAlastmodified[$i]} | od -c
The output is:
+ echo '1408039118'
+ od -c
0000000 1 4 0 8 0 3 9 1 1 8 033 [ m 033 [ K
0000020 \n
0000021
But now I'm not sure how to read this. I understand the newline character is belonging to the echo command. But what is 033 [ m 033 [ K exactly? And does this belong to my issue?
I also tried running that number through bc:
echo ${depsAlastmodified[$i]} | bc | od -c
This is the output:
+ echo '1408039118'
+ bc
+ od -c
(standard_in) 1: illegal character: ^[
(standard_in) 1: syntax error
(standard_in) 1: illegal character: ^[
(standard_in) 1: illegal character: K
0000000
Something is wrong with that variable. What else could I try? How to fix this?
Just for reference, this is the full issue history.
Looks like you have trailing characters in your array.
Try this with tr -cd '[[:digit:]]' which will delete all non digits from input:
echo "${depsAlastmodified[$i]}" | tr -cd '[[:digit:]]' | od -c
It should give:
0000000 1 4 0 8 0 3 9 1 1 8
0000012
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With