I need to create a BASH conditional that checks if any unusual characters are found. If any character is not one of these, the conditional returns true:
if [[ "$variable" contains something that is not [cdfghZ,?!] ]] then echo "The variable contains an unknown character." fi
How can I check for characters not found in a list with a BASH conditional?
You can use
[[ "$variable" == *[^cdfghT,?\!]* ]]
! needs to be used as
\! to escape history event expansion.