How to read variable with no display

I'll be reading user name and password from the person while running a shell
script so that he is authenticated.

The challenge here is to read the password variable without displaying on screen. Is there a way?

I presently do it displaying it on the screen as

echo " please enter your password"
read password

Is there a way to read it with no display like unix does when we log in?Please
advise. :confused:

# save the old terminal settings
oldmodes=`stty -g`
# disable terminal 'echo' - blind typing
stty -echo
# read user input/password
read password
# restore 'old' terminal settings
stty $oldmodes

Thanks a lot.It worked!! :slight_smile:

Is it possible to read the username being on the same line ,
like login: Sheetal instead of
login:
Sheetal

Eg: when i say in my script
echo "login"
read username

and run this, it should be displayed as
login:_
where '_' is the cursor position for me to type

Thanks,
Sheetal

echo -n doesn't print a newline the way echo usually does. But users will be able to backspace over the prompt.

Thanks a lot for your help

Sorry i didnt mention that i am using ksh shell, and as per man pages for echo
"In addition, ksh's echo, does not have a -n option. :frowning: "

doesnt matter ...i will try with sh/csh

I think I asked for too much :frowning:
My script is as follows
#!/bin/csh
echo -n "login: "
read login
echo $login

When i run the script
jolt% ./test_read.csh
login: sheetal
login: Undefined variable

I dont think we can use read in csh (doubtful ???) Any other ideas? Just curious to know if it will work.

Thanks

you can use printf in ksh

printf "login : "

See scripting password prompts

Thanks Perderabo