0

I want to check if a string does not contain any letters, I figured out how to check whether a string does contain any letters but I don't know how to inverse it so I don't have to go to the else block.

if [[ $var =~ [a-zA-Z] ]]; then
        echo ""
    else
        echo -e "$ERROR, no description"
    fi
Nv9zEs
  • 5
  • 2
  • Did you try `if ! [[ $var =~ [a-zA-Z] ]]; then...`? Or just change the regex to `^[^a-zA-Z]+$` (all characters from beginning to end don't match a letter). – lurker Feb 03 '22 at 12:17
  • Yeah `!` did solve my problem – Nv9zEs Feb 03 '22 at 12:51

0 Answers0