So I want to validate a response of a user in tcsh script and that's what I have so far
set var1="temp"
while($var1 != [yY] && $var1 != [Yy][Ee][Ss] && $var1 != [Nn] && $var1 != [Nn][Oo])
echo "Do you want to create a backup directory ? :"
set response=&<
if ($response == [yY] || $respose == [Yy][Ee][Ss]) then
mkdir backup
echo "Backupd directory created \n"
else if($response == [nN] || $response == [Nn][Oo]) then
echo "No backup directory is created \n"
else
echo "Please enter a valid respose ! \n"
var1=$response
endif
end
I basically want the user to either input Y,y,Yes,N,n,No and of course I also allow for a combination of small case and upper case in yes and now.
But when I run the script, it gives me an error saying [yY]: No match.
So I am guessing something is wrong when comparing $var1 to [Yy]. Basically I am validating the user input.
And cai reassign var1
like I did, var1=$response
, or do I have to use set again >