-1

As the tittle states, I just want the line to test if the variable is greater than 10 but less than 30 but it returns an error of "too many arguments"

if [ -f myClass ] && grep 'John Smith' myclass > /dev/null

then cat myclass

elif [ -f grades ]

then

grep "s100" grades

elif
[ $ca82 -gt 10 -a $ca82 -lt 30 ]

then
echo "success"

else
echo "test 2"

fi
mrwejuvey
  • 11
  • 3
  • 1
    Your use of `-a` is not wrong. You just need to quote your variable as shown in my answer. – perennial_noob Apr 04 '19 at 21:56
  • 2
    @perennial_noob extract from shellcheck:` ^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.` – itChi Apr 04 '19 at 22:25
  • 2
    But note that ```The XSI extensions specifying the -a and -o binary primaries and the '(' and ')' operators have been marked obsolescent. ```. This should be written `[ "$ca82" -gt 10 ] && [ "$ca82" -lt 30 ]` – William Pursell Apr 04 '19 at 23:01

3 Answers3

1
elif [ $ca82 -gt 10 ] && [ $ca82 -lt 30 ]

Providing you've set $ca82 somewhere

itChi
  • 642
  • 6
  • 19
0

What you need is the quotes around the variable itself. Rest of it is fine. So:

[ "$ca82" -gt 10 -a "$ca82" -lt 30 ]
perennial_noob
  • 459
  • 3
  • 14
0

Your code should work if cat82 is a number but it has an space in it. That's why test command complaints of too many arguments.