Unable to bash: syntax error: invalid arithmetic operator (error marker - "")

I know there have been many similar questions here, but this is quite important, please read.

I have a bash script that does nothing but compare two numbers, basically like this:

[[ 1408039118 -lt 1401215749 ]]

      

Now running the script throws the following error:

/usr/bin/pacaur: line 179: 1408039118: syntax error: invalid arithmetic operator (error token is "")

      

So my understanding is that 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 nothing wrong. I tried some more debugging using od -c

for this variable:

echo ${depsAlastmodified[$i]} | od -c

      

Output:

+ 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 that the newline character belongs to the echo command. But what 033 [ m 033 [ K

exactly is it? And does this apply to my problem?

I also tried to run this number via bc

:

echo ${depsAlastmodified[$i]} | bc | od -c

      

This is the conclusion:

+ 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

      

There is something wrong with this variable. What else could I try? How to fix it?

For reference, this is the complete release history .

+3


source to share


2 answers


It has something to do with grep adding color at the end of the line,

It is actually not an easy task to track this down and fix it. For reference, if anyone else is facing this problem: I had it GREP_OPTIONS="--color=always"

in my ~\.bashrc

file to fix this, you need to do the following:



  • Uninstall pacaur, remove complete directory / tmp / pacaurtmp - * /.
  • Place GREP_OPTIONS="--color=never"

    (or auto

    ) in yours ~/.bashrc

    and source ~/.bashrc

    his.
  • Reinstall pacaur and update the entire system pacaur -Syu

+1


source


It looks like you have trailing characters in your array.

Try this with a help tr -cd '[[:digit:]]'

, which will remove all insignificant digits from the input:

echo "${depsAlastmodified[$i]}" | tr -cd '[[:digit:]]' | od -c

      



He should give:

0000000   1   4   0   8   0   3   9   1   1   8
0000012

      

+4


source







All Articles