How to check if a string contains a special character (!@#$%^&*()_+)
This is portable to Dash et al. and IMHO more elegant.
case $str in
*['!&()'@#$%^*_+]* ) echo yup ;;
esac
Match it against a glob. You just have to escape the characters that the shell otherwise considers special:
#!/bin/bash
str='some text with @ in it'
if [[ $str == *['!'@#\$%^\&*()_+]* ]]
then
echo "It contains one of those"
fi