Camouflage STD IN on output (TRU64)


 
Thread Tools Search this Thread
Operating Systems Solaris Camouflage STD IN on output (TRU64)
# 1  
Old 02-07-2011
Camouflage STD IN on output (TRU64)

Hi guys, i have a new problem, even in scripting on KSH.
Given a string by standard INPUT (keyboard), i need to replace each character i print with this one '#' .
It's to camouflage password while digiting on command line.

For example:

----------------------------------
prompt$ example.ksh (enter)
insert password:


----------------------------------

and while i digit my passwd i must print on STD OUT the character # for each character.

Help me please! Smilie
# 2  
Old 02-07-2011
How about stty -echo before you read the password, and stty echo after? Depending on your shell this may stop the characters from appearing at all.

---------- Post updated at 11:25 AM ---------- Previous update was at 11:15 AM ----------

In more detail, I mean like this:
Code:
stty -echo
        printf "%s" "Input password: "
        read PASS
        echo
stty echo
echo "pass was $PASS"

I don't think vanilla ksh88 has any facility for reading characters one-at-a-time, so this may be the best you can do with a pure shell solution.
# 3  
Old 02-07-2011
This is a modification to a post by user 'LivinFree', a long time ago:

Code:
trap 'stty "$oldstty"; exit' 0

readString () {
  printf "Enter password: "
  oldstty=`stty -g`
  stty -icanon -echo min 1 time 0
  while :; do
    K=$(dd bs=1 count=1 2>/dev/null) 
    [ ! "$K" ] && break
    S=$S$K
    printf ${K:+#}
  done
  stty "$oldstty"
  echo
}

readString
echo "You entered: $S"

I just tested it in KSH on Solaris 10, so you could try it.

Last edited by Scott; 02-07-2011 at 01:52 PM.. Reason: It can go a bit doolally if you press ^C, so added 'trap'
This User Gave Thanks to Scott For This Post:
# 4  
Old 02-08-2011
Thank u guys, i supposed that didn't exist a single command or option that get single char by stdin.I knew something about "stty -echo" but never tried.
I'll try your methods and will report you.

Thank u again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

std::cout and gfortran print*, don't output to the screen

I am not sure where to post this other than here. I am trying to figure out why an app gives different output when compiled under Ubuntu 10.10 and CentOS 5.5. I am pretty sure that the issue is that the Cent version has gcc 4.1 installed, while Ubuntu has gcc 4.4. I am trying to print from some... (20 Replies)
Discussion started by: LMHmedchem
20 Replies

2. Programming

std::reverse_iterator in Sun C++

Hi, I'm having trouble compling the following code in Sun C++ (under sun studio 10). I found that it is issue with libCstd library. It can be resolved if i used stdport lib. However, i have no choice but to use libCstd. Does anyone know what can be done to resolve the issue? :confused: ... (0 Replies)
Discussion started by: shingpui
0 Replies

3. Shell Programming and Scripting

Help with Getopt::Std

I am working on a script that lists files in a directory with a few file attributes depending on what option the user specifies at the command prompt. The script uses Getopt::Std and takes two switches. The first switch allows the user to specify a directory, the second switch gives a long... (3 Replies)
Discussion started by: Breakology
3 Replies

4. Shell Programming and Scripting

read from std i/p with timeout within a script

hello every one , this is my first participation in the forum , I hope it'll be a good start within a script I would like to put some code to read i\p from standard i\p using read command if it reads Y it will terminate the script if it reads N it will continue execution , if no i\p is... (2 Replies)
Discussion started by: Blue_shadow
2 Replies

5. UNIX for Advanced & Expert Users

redirect to both file and std output at the same time

hello can some one please help me to redirect the output of a command to both std output and a file. this is little urgent. sridhar (2 Replies)
Discussion started by: send2sridhar
2 Replies

6. AIX

Redirecting Both to a file and std output

Hello Friends, Can some one help me how to redirect output of a file to both a file and std output? All the help would be greatly appreciated. Regards Sridhar (1 Reply)
Discussion started by: send2sridhar
1 Replies

7. Shell Programming and Scripting

redirecting std error

Hi, I use the following command make all > output-`date +%F-%H-%M-%S`.txt 2>&1 to invoke a MAKE process that takes some weeks to complete. The ouput is redirected to a text file. Now I prefix the above command with time to get time needed for completion of the MAKE process time make... (2 Replies)
Discussion started by: gkamendje
2 Replies

8. Shell Programming and Scripting

reading from within the loop --std i/p problem

i have a teat file having data like one 12/3 two 23/09 three 12/12 now from another script i want to read one line at a time ,cut field one and two in two separate variable ,compare field1 with another variable but outside the loop .If i found a match i want to take from user the value... (2 Replies)
Discussion started by: mobydick
2 Replies

9. Programming

Sun Studio C++ - Getting error in linking std::ostream &std::ostream::operator<<(std:

Hello all Im using CC: Sun C++ 5.6 2004/07/15 and using the -library=stlport4 when linkning im getting The fallowing error : Undefined first referenced symbol in file std::ostream &std::ostream::operator<<(std::ios_base&(*)(std::ios_base&))... (0 Replies)
Discussion started by: umen
0 Replies

10. Shell Programming and Scripting

How to redirect std out and std err to same file

Hi I want both standard output and standard error of my command cmd to go to the same file log.txt. please let me know the best commandline to do this. Thanks (2 Replies)
Discussion started by: 0ktalmagik
2 Replies
Login or Register to Ask a Question