Quoting.
In the script, use "$1" rather than just $1.
On the command line, use
./script '*(ontehu'
instead of
./script *(ontehu
./script.sh (abcThis is a syntax error in the shell grammar../script.sh &&This makes the shell think there is a conditional AND on the command line and it expects something on the right hand side of the&&operator../script.sh &abcThis is two commands:./scriptstarted as a background process (with&), and the commandabc.
In all these cases, the argument should be quoted (single quoted, ideally, unless you need the shell to insert the value of a shell variable, in which case it should be double quoted).
Your script:
if [[ $1 =~ ^[A-Za-z_]+$ ]]; then
echo it matches
else
echo does_not match
fi
Quote $1:
if [[ "$1" =~ ^[A-Za-z_]+$ ]]; then
echo it matches
else
echo does_not match
fi
Allow digits in the tail end of the value:
if [[ "$1" =~ ^[A-Za-z_][A-Za-z0-9_]+$ ]]; then
echo it matches
else
echo does_not match
fi
Do proper reporting of errors (this is extra):
if [[ "$1" =~ ^[A-Za-z_][A-Za-z0-9_]+$ ]]; then
printf '"%s" is a valid variable name\n' "$1"
else
printf '"%s" is not a proper variable name\n' "$1" >&2
exit 1
fi