Reputation: 11824
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.
Upvotes: 3
Views: 8093
Reputation: 11824
It has something to do with grep adding color escape stuff at the end of line,
It's really no easy task to track this down and fix this.
For reference, if anyone else comes across this issue:
I had GREP_OPTIONS="--color=always"
in my ~\.bashrc
file, to fix this, you need to do the following:
GREP_OPTIONS="--color=never"
(or auto
) into your ~/.bashrc
and source ~/.bashrc
it.pacaur -Syu
Upvotes: 1
Reputation: 785481
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
Upvotes: 4