What's new

Unix assign problem (1 Viewer)

Ronan

Auditioning
Joined
Jul 5, 2001
Messages
6
part of my assignment is, to write a script 'C shell' to accept any user ID. containing the any of the following characters ' y r e w q s ' in any position of the user ID.

So far I have the easy part done.

Now I need to search the user's ID for one of the characters above and if it contains one accept the ID.

prempt:

onintr interrupt

echo "Welcome to the UNIX O/S."

set password = y

echo -n "Enter your password: "

set code = `head -1`

while ("$password" != "$code")

echo "Wrong password."

echo -n "Enter your password again: "

set code = `head -1`

end

echo "correct password"

exit 0

interrupt:

echo "Do not try to terminate by pressing ^c!"

goto prempt

If anyone is able to sugest a solution I would be very greatful.
 

Kevin P

Screenwriter
Joined
Jan 18, 1999
Messages
1,439
Replace this line:
while ("$code" !~ *[yrewqs]*)
This works in tcsh in Linux, at least.

Basically it's saying "while (the password you entered) does not contain any of y r e w q s in any position (the asterisks allow any characters before and after). This is known as "globbing" in C shell terminology, or pattern matching. It's similar to the wildcards used to find files.

KJP
 

DonRoeber

Screenwriter
Joined
Feb 11, 2001
Messages
1,849
Interesting script. But just for claritys sake, the shell doesn't handle user authentication.... on most systems, its handled by the 'login' program. So you'd need to rewrite the C code for the login program. Or, if your version of login supports PAM, you could probably write a PAM module, and have login use that.
 

Ronan

Auditioning
Joined
Jul 5, 2001
Messages
6
Thanks Kevin it worked nicely.
I was thinking that if I set had set six passwords = to
= *y*
= *r*
= *e*
= *w*
= *q*
= *s*
and use an elseif statement.
I know this would be longer but I never knew about globbing before. would it have worked.
well anyway I used your code and I was as happy as larry
many thanks;) ;) ;) ;) ;)
 

Glenn L

Stunt Coordinator
Joined
Jun 21, 1999
Messages
56
(*dusts off his account*)
The tcsh solution is nifty, but won't pass in regular csh. Use grep...
while (echo $code | grep '[yrewqs]' >&! /dev/null)
:)
 

Users who are viewing this thread

Top