I'm trying to check if an input is an integer and I've gone over it a hundred times but don't see the error in this. Alas it does not work, it triggers the if statement for all inputs (numbers/letters)
read scale
if ! [[ "$scale" =~ "^[0-9]+$" ]]
then
echo "Sorry integers only"
fi
I've played around with the quotes but either missed it or it did nothing. What do I do wrong? Is there an easier way to test if an input is just an INTEGER?
if [[ $scale =~ [^0-9] ]]
is less convoluted. Doing so, puts the negation in the regular expression instead of the test condition. See below. – Serge Stroobandt Apr 14 '22 at 16:04