Fish Fish -4 years ago 324
Bash Question

Integer expression expected error with shell script

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 ]
echo -e "\t\t\033[91;4m
elif ! [ $col -le 12 ]

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

./ line 259: [: .",: integer expression expected
./ 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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download