How to read variable with no display


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read variable with no display
# 1  
Old 05-12-2006
CPU & Memory 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. Smilie
# 2  
Old 05-12-2006
# 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
# 3  
Old 05-12-2006
MySQL

Thanks a lot.It worked!! Smilie
# 4  
Old 05-24-2006
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
# 5  
Old 05-24-2006
echo -n doesn't print a newline the way echo usually does. But users will be able to backspace over the prompt.
# 6  
Old 05-24-2006
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. Smilie "

doesnt matter ...i will try with sh/csh
# 7  
Old 05-24-2006
I think I asked for too much Smilie
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Read the line from the last and display the one which is non-zero

Hi All, My requirement is this. Am trying to find a one liner unix command, which will check the last line of the file for 0. If it is zero, it would pick the previous line, else it should display the last line. Eg: abcd efgh ijhk 0 0 Output expected -- ijhk Please share your... (8 Replies)
Discussion started by: hariniiyer300
8 Replies

2. Shell Programming and Scripting

Variable arangement to display

Hello For this future package for community, i'd like to know your preference on this presented 'issue'. Writing some commands which will display some strings, using another command supporting 3 strings to be supplied, i wonder how the 'default output' should look like. Let me use a... (2 Replies)
Discussion started by: sea
2 Replies

3. Shell Programming and Scripting

a little help with using AWK to display whats being read in

I am making a script that reads in the model of a car and then searches a file and displays the make model and price of anything matching the input provided. here is what I have so far #!/bin/sh echo Please enter a car model: read model if test $? -eq 0 then grep $model /home/cars awk... (4 Replies)
Discussion started by: subway69
4 Replies

4. Emergency UNIX and Linux Support

Grab total page read from webalizer display in html

Hi, I need a way to grab the total combines since inception, total pages read from webalizer on my centos server or any other location (as long as since inception) and display the result live on my website So with each visit it would be increasing, or perhaps live (ajax) not sure But can... (0 Replies)
Discussion started by: lawstudent
0 Replies

5. Shell Programming and Scripting

Read File and Display The Count of a particular field

Hi Mates, I require help in the following: I have the following file snmp.txt Wed Mar 2 16:02:39 SGT 2011 Class : mmTrapBladeS origin : 10.0.0.0 hostname : 10.0.0.2 msg : IBM Blade Alert: Calendar Index : 10.0.0.2-IBMBLADE Fri Mar 4 07:10:54 SGT 2011 Class : mmTrapBladeS... (2 Replies)
Discussion started by: dbashyam
2 Replies

6. UNIX for Dummies Questions & Answers

DISPLAY Environment Variable

I've seen articles which say "export DISPLAY=<IP>:0" and others which say "export DISPLAY=<IP>:0.0". Can someone explain what the difference is? TIA (4 Replies)
Discussion started by: cjhancock
4 Replies

7. Shell Programming and Scripting

Can I use read to read content of a variable

Can I use the read command to read the contents of a variable? I'm trying by using the following code and getting nothing back. I'm in a Linux environment. #!/bin/ksh IFS=~ VAR1=1~2~3~4 echo $VAR1 | read a b c d print "$a $b $c $d" (9 Replies)
Discussion started by: nmalencia
9 Replies

8. UNIX for Dummies Questions & Answers

How to export the Display variable

I'm trying to open an xwindow on my Sun server. What am I doing wrong? # echo $SHELL /sbin/sh # # export DISPLAY=localhost:0.0 DISPLAY=localhost:0.0: is not an identifier Thank you! (1 Reply)
Discussion started by: FredSmith
1 Replies

9. UNIX for Dummies Questions & Answers

Display from a variable using echo.

I have a variable that is outputting a lot of space. here has been 45 lines returned ... how can I remove the spaces between the "been and the 45" CODE: fil_len=`wc -l < coshb.txt` if ; then cat coshb.txt | more echo " " echo "There has been ${fil_len} lines... (4 Replies)
Discussion started by: jagannatha
4 Replies

10. Cybersecurity

Display variable

Hi: Im trying to change the display setting from my Linux server to Linux workstation but a Refused connection by server appear. The first task that I doing is to export the DISPLAY variable on my Linux Workstation so I tried to execute several X programs with the Refused Connection message.... (2 Replies)
Discussion started by: dansanmex
2 Replies
Login or Register to Ask a Question