3

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.

3
  • It doesn't address your issue directly but in bash, you can (should?) use (( depsAlastmodified[i] < 1401215749 )) for your comparison. Commented Aug 17, 2014 at 11:52
  • This one tells me the oposite stackoverflow.com/a/17526818/1260906 Commented Aug 17, 2014 at 12:16
  • 3
    The trailing characters look like ANSI escape codes for resetting the color and erasing part of the line, respectively. How does your array get set? Commented Aug 17, 2014 at 12:52

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

Comments

1

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:

  • Uninstall pacaur, remove the complete /tmp/pacaurtmp-*/ directory.
  • Put GREP_OPTIONS="--color=never" (or auto) into your ~/.bashrc and source ~/.bashrc it.
  • Reinstall pacaur and do a whole system upgrade pacaur -Syu

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.