The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Command display output on console and simultaneously save the command and its output satimis UNIX for Dummies Questions & Answers 7 01-25-2009 08:27 PM
password verification verify password of a user for only first 8 characters amitpansuria UNIX for Advanced & Expert Users 12 10-23-2008 11:03 AM
console '# ' with {PWD} ?? gfca UNIX for Advanced & Expert Users 2 08-14-2008 08:08 PM
Change password by pushing encrypted password to systems benq70 UNIX for Dummies Questions & Answers 1 09-02-2005 10:08 AM
Console Log kdreaves UNIX for Dummies Questions & Answers 4 05-21-2004 06:13 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-19-2008
codeman007 codeman007 is offline
Registered User
  
 

Join Date: Sep 2008
Location: US
Posts: 32
how to display password as * in the console

Hi,
I have to read the password input and display it as * in the console

How can I do this??
  #2 (permalink)  
Old 12-19-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,934
This works for ksh93 and should be easily modifable for bash.

Code:
passwd=""
omodes=`stty -g`

echo "Enter Password: \c"
while :
do
   stty raw
   c=$(dd bs=1 count=1 2>/dev/null)
   stty -raw

   # break out of loop if CR found
   [[ -z $(echo $c | tr -d "\015") ]] && break

   stty echo
   echo "*\c"
   passwd=${passwd}${c}
   stty -echo
done

stty $omodes

echo
echo "Password entered: $passwd"

  #3 (permalink)  
Old 12-19-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,934
For bash, the only change needed is to explicitly tell the build-in echo command to interpret "\c" correctly i.e.

Code:
passwd=""
omodes=`stty -g`

echo -e  "Enter Password: \c"
while :
do
   stty raw
   c=$(dd bs=1 count=1 2>/dev/null)
   stty -raw

   # break out of loop if CR found
   [[ -z $(echo $c | tr -d "\015") ]] && break

   stty echo
   echo -e "*\c"
   passwd=${passwd}${c}
   stty -echo
done

stty $omodes

echo
echo "Password entered: $passwd"

I love the idiosyncrasies of the echo command!
  #4 (permalink)  
Old 12-19-2008
crs6785 crs6785 is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 3
if your looking for a simple solution to just hide the password, and you're using bash, you could just use "read -s" ...


Code:
#!/bin/bash

echo -n "Enter a Password: " 
read -s pass_value
echo ""
echo "Password Entered: $pass_value"

  #5 (permalink)  
Old 12-21-2008
codeman007 codeman007 is offline
Registered User
  
 

Join Date: Sep 2008
Location: US
Posts: 32
Thanks for all the replies.
In bash when i type the password it prints the first character on screen
and then types * correctly....but the input is correct

How can i overcome this??
  #6 (permalink)  
Old 12-21-2008
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,127
My script is here: Reading password and echo * character but it is ksh.
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0