2

im a real noob with this, sorry if this is a stupid question

heres a clip of the code

(first line is line #259, last line is #263)

if [ $col -le 6 ]
then
echo -e "\t\t\033[91;4m
$paragraph\033[0m"
elif ! [ $col -le 12 ]

when i run it this is what i get when i run it

./checker.sh: line 259: [: .",: integer expression expected
./checker.sh: line 263: [: .",: integer expression expected

when i looked up this error it said to make sure there is a space in between the bracket and i have a bracket. im not sure what else to do.

2
  • Check the value of $col. It almost certainly isn't what you expect it is. (And, in fact, would appear that it is .\", somehow. Commented Aug 26, 2016 at 2:42
  • Possible duplicate of Error "integer expression expected" in script Commented Aug 26, 2016 at 4:08

1 Answer 1

2

Error messages are informative if you study how to read them.

Let's run three examples:

$ col="1"; [ $col -le 6 ]
$ col=""; [ $col -le 6 ]
bash: [: -le: unary operator expected
$ col="a"; [ $col -le 6 ]
bash: [: a: integer expression expected

Of these three, you obtained the message: "integer expression expected". That means that your col is not an integer.

To reproduce the message you see, we set col=' .",':

$ col=' .",'; [ $col -le 6 ]
bash: [: .",: integer expression expected
Sign up to request clarification or add additional context in comments.

4 Comments

that's just the part of the script that giving me the error. would it help if i put the entire script in?
You could just look for the part that sets the value of col. If it is not clear where that is, then run bash -x checker.sh. This will produce a lot of diagnostic output. Search through the output for where col is set and look for why it is set to the wrong value.
col=() which means it's set to nothing if I'm correct
Yes, that is right. More precisely, col=() means that it is set to an empty array. For the code shown in the question to work, you need col set to a number.

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.