=to compare as string (or use
$varto expand as a variable).
read -r n if [ n -lt 0 ] then echo "bad input" fi if [ "$USER" -eq root ] then echo "You are root" fi
read -r n if [ "$n" -lt 0 ] # Numerical comparison then echo "bad input" fi if [ "$USER" = root ] # String comparison then echo "You are root" fi
You are comparing a string value with a numerical operator, such as
-gt. These only work for numbers.
If you want to compare the value as a string, switch to the equivalent string operator:
If you want to compare it as a number, such as
n=42; while [ n -gt 1024/8 ]; .., then keep the operator and expand the operands yourself with
while [ "$n" -gt $((1024/8)) ]
ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.