home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 45.26 Quoted hereis Document Terminators: sh vs. csh Chapter 45
Shell Programming for the Initiated
Next: 45.28 Quick Reference: expr
 

45.27 Turn Off echo for "Secret" Answers

When you type your password, UNIX turns off echoing so what you type won't show on the screen. You can do the same thing in shell scripts with stty -echo .


stty
 




read
 

#!/bin/sh
   ...
trap 'stty echo; exit' 0 1 2 3 15
# use the right echo for your UNIX:
echo "Enter code name: \c"
#echo -n "Enter code name: "
stty -echo
read ans
stty echo
   ...

The response is stored in $ans . The trap (44.12 ) helps to make sure that, if the user presses CTRL-c to abort the script, characters will be echoed again.

- JP


Previous: 45.26 Quoted hereis Document Terminators: sh vs. csh UNIX Power Tools Next: 45.28 Quick Reference: expr
45.26 Quoted hereis Document Terminators: sh vs. csh Book Index 45.28 Quick Reference: expr

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru