I've been trying to make a condition in a bash script which will tell me if the given string contains chars other than letters or a hyphen.
i.e, this is a legal string: hello-world
and that one is not: hello-123-there
This is what I have tried so far but I think I also have a logic mistake:
if ! [[ "$1" == *-* ]] && ! [[ "$1" =~ ^[a-zA-Z]+$ ]] ; then
echo "the line is bad"
exit
fi
(while $1 refers to the string, of course). Would love to get some help from you.