I try to match a user-typed string with a specific pattern, to be exact i want to check if the string starts with an upper case letter and then continues with any upper, lower-case letter or number. I want to do this in tcsh, I know bash is better to use, but I have to use tcsh.
So basically i want the following in tcsh:
if [[ $name =~ ^[A-Z][A-Za-z0-9]*$ ]]
Here is my code so far:
#!/bin/tcsh
set name
while ( $name == "" )
echo 'Give an account name!'
set name = $<
if ( $name =~ '^[A-Z][A-Za-z0-9*$]' ) then
echo 'Name accepted!'
else
echo 'Not correct format!'
set name = ""
endif
end
I'm continously ending up in the "else" part. Thank you very much for the help!