Q:

Making a simple Bash script to generate palindromes via the 196 algorithm

For no particular reason, I want to make script that automates the 196 algorithm. In the even of Lychrel numbers being found, the code will just throw out an overflow error. My code is as follows.
#!/bin/bash
echo -n "Enter Natural Number above 10 as Maximum > "
read max;
if [[ $max <= "10" || $max =~ ^[0-9]+$ ]];
then
    echo "Improper input. Rerun Script."
    exit 1
else
    for int in {10..$max}
    do
        int2=$int
        while [[ $int2 != `echo $int2 | rev` ]]
        do
            int2=$(expr $int2 + $(echo $int2 | rev))
        done
        echo $int2 >> Palindrome.txt
        echo `awk '!a[$0]++' Palindrome.txt` > Palindrome.txt
    done
    exit 0
fi

And it seems my code spits out an error no matter what, on line 4.
Enter Natural Number above 10 as Maximum > test
./Palindrome.sh: line 4: syntax error in conditional expression
./Palindrome.sh: line 4: syntax error near `"10"'
./Palindrome.sh: line 4: `if [[ $max <= "10" || $max =~ ^[0-9]+$ ]];'

How can I fix line 4? Am I using "exit" correctly? The conditional on line 4 is supposed to detect if the string is below 10, or is not an integer.

A:

This needs to be changed from
[[ $max <= "10" || $max =~ ^[0-9]+$ ]]

to 
[[ $max -le "10" || $max =~ ^[0-9]+$ ]]

-le → less equal
-lt → less than
-ge → greater equal
-gt → greater than
Also, I'm not sure if this makes sense, I assume you actually meant:
# is a number and less or equal 10
[[ "$max =~ ^[0-9]+$ && $max -le "10" ]]

You want to check first if it's a number and then if it's less than 10. If you do it the other way around, you'll get an error because SOME_RANDOM_TEXT_READ -le "10" is not valid if the input isn't a number. Also, you want to use double quotes for "$max" otherwise it won't work if there is a space in the input.

