I am having problems using a bash script to read the input from the user and checking that its a valid number. I only want the user to input a maximum of a 3 number string (321 , 521 , 871 etc.). Anything longer or that includes a chararcter or symbol will display an error message.
heres what i have got so far
read input
for ((x=1;x<4;x++)){
v=`echo $input | cut -c $x`
if [ $v !-eq (0-9) ]
then
echo "error"
else
continue
fi
}
What exactly do you want to check with that?
The proper syntax in shell would be:
if ($x>999); then
something
fi
and it will fail in most cases.
Have you only tried your command?
terminal80:~# x=abc
terminal80:~# if ($x>999); then echo wrong; else echo right; fi
-bash: rty: command not found
right
terminal80:~# x=123
terminal80:~# if ("$x">999); then echo wrong; else echo right; fi
-bash: 123: command not found
right