Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I turn off echo in a terminal?

Tags:

terminal

unix

sh

I'm writing a Bourne shell script and have a password input like this:

echo -n 'Password: '
read password

Obviously, I don't want the password being echoed to the terminal, so I want to turn off echo for the duration of the read. I know there's way to do this with stty, but I'll ask the question for the benefit of the community whilst I go read the manpage. ;)

like image 640
Josh Glover Avatar asked Apr 12 '11 10:04

Josh Glover


People also ask

How do I use the echo command in terminal?

Writing Text to the Terminal To write a simple string of text to the terminal window, type echo and the string you want it to display: echo My name is Dave. The text is repeated for us.

What does echo in terminal mean?

In computing, echo is a command that outputs the strings that are passed to it as arguments. It is a command available in various operating system shells and typically used in shell scripts and batch files to output status text to the screen or a computer file, or as a source part of a pipeline.

What does echo do in terminal mac?

This prints the specified text string before producing a listing of all the files in the current working directory, across the screen. echo recognizes a number of escape sequences which it expands internally. An escape command is a backslash-escaped character that signifies some other character.

What does @echo do in CMD?

The echo command repeats typed text back to the screen and can send text to a peripheral on the computer, such as a COM port.


3 Answers

stty_orig=`stty -g`
stty -echo
echo 'hidden section'
stty $stty_orig
like image 144
Sandro Munda Avatar answered Oct 14 '22 14:10

Sandro Munda


read -s password works on my linux box.

like image 40
Rumple Stiltskin Avatar answered Oct 14 '22 13:10

Rumple Stiltskin


You can use '-s' option of read command to hide user input.

echo -n "Password:"
read -s password
if [ $password != "..." ]
then
        exit 1; # exit as password mismatched #
fi

Also you can use 'stty -echo' if you want to hide from terminal to print. And restore the terminal settings using "stty echo"

But I think for getting password input from user 'read -s password' is more than enough.

like image 29
PravinY Avatar answered Oct 14 '22 13:10

PravinY