The first command line argument is available as $1. A valid shell variable name starts with a alphabetic character (or underscore) and continues with alphanumerics (or underscores).
Two shell patterns that matches an invalid shell variable name is
[!a-zA-Z_]*
and
[a-zA-Z_]*[!a-zA-Z_0-9]*
You may use case ... esac to do pattern matching against a variable's value.
Spoiler warning:
#!/bin/sh LC_ALL=C case "$1" in [!a-zA-Z_]*|[a-zA-Z_]*[!a-zA-Z_0-9]*|_|""9]*|"") echo 'NO' ;; *) echo 'YES' esacThis also answers "NO" for a variable whose name is just an underscore, or whose name is empty. Note that this is using shell globbing patterns, not regular expressions, and that it runs in any POSIX shell, not justbash.
Testing:
$ ./script.sh _ae
YES
$ ./script.sh 0a9oe
NO
$ ./script.sh aoeat
YES
$ ./script.sh aoeat-aoe
NO