read from terminal/keyboard > /dev/tty


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers read from terminal/keyboard > /dev/tty
# 1  
Old 08-07-2010
read from terminal/keyboard > /dev/tty

Hi,

I need to provide more than one character to "> /dev/tty" through terminal/keyboard input, I have this:

Code:
ok=false
while [ $ok = false ]
do
echo " Enter r1 to reformat "
> /dev/tty
read choice
case $choice in
         [r1])
         echo " bla bla bla "
         ;;
done

However, in this way, I just can provide one character, I can enter "r" or "1" alone. I need to enter "r1" instead. Is it possible to keep it simple using the " > /dev/tty " form?

Thanks in advance,
# 2  
Old 08-07-2010
Hi.

Unless I'm not understanding, can you not just use:

Code:
ok=false
while [ $ok = false ]
do
echo " Enter r1 to reformat "
> /dev/tty
read choice
case $choice in
         r1) # without the [ and ]
         echo " bla bla bla "
         ;;
done

I'm not sure what the > /dev/tty is supposed to being doing here. You also forget to set ok to true?

Last edited by Scott; 08-07-2010 at 01:35 PM.. Reason: grammar
# 3  
Old 08-07-2010
Thank you so much, it works perfectly now. I was surfing in internet and thought the problem was > /dev/tty, but it's not, the problem was the []. Thanks again. I'm using the ok=false to set a loop, this small example is inside a greater loop.
# 4  
Old 08-07-2010
Great Smilie

For a moment, I though you wanted to type r1 and not have to press Enter afterwards.

I saw this useful thread:

https://www.unix.com/unix-dummies-que...ser-input.html

Based on that...

Code:
readOne () {
oldstty="`stty -g`"
stty -icanon -echo min 1 time 0
dd bs=1 count=1 2> /dev/null #>/dev/null 2>&1
stty "$oldstty"
echo
}

readWord() {
  while true; do
    unset STR
    C=0
    printf "Enter '$1' to continue: "
    while [ $C -lt ${#1} ]; do
      E=$(readOne)
      [ -z "$E" ] && break
      STR=$STR$E
      C=$((C+1))
    done
    [ "$STR" = "$1" ] && break
    echo "Invalid string.  Please try again!"
  done
}

readWord r1

edit: ah.. just noticed it works in Bash, and not ksh Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simply question about capturing output to /dev/tty

Suppose another person wrote the following one-line shell script: echo $RANDOM > /dev/tty QUESTION #1: How can the random number, which is output to the terminal by this script, be captured in a variable? QUESTION #2: How can this be done in a cron job? Specific code, whether in ksh or... (1 Reply)
Discussion started by: Paul R
1 Replies

2. UNIX for Dummies Questions & Answers

Reading password from /dev/tty

hi, From the below script: ##########################################pwd_auth.sh######################################################################################## #Author: Pandeeswaran Bhoopathy #Written on:26th Jan 2012 2:00PM #This script describes the feature of stty and illustrates... (3 Replies)
Discussion started by: pandeesh
3 Replies

3. UNIX for Dummies Questions & Answers

/dev/tty find last modified time

what can I use to find the last modified time of a /dev/tty ? (4 Replies)
Discussion started by: l flipboi l
4 Replies

4. Programming

Create a pipe to /dev/tty

Hello everybody: I have a child process which reads a password from /dev/tty, as far as I know file descriptors for the child process can be seen by using lsof, so I want to connect to such device in order to send the password through a pipe, how could I do that? (2 Replies)
Discussion started by: edgarvm
2 Replies

5. Programming

What happens on opening /dev/tty failure?

Since the existence of /dev/tty is not guaranteed, what happens when an attempt is made to open /dev/tty and there's no controlling terminal? Will it fail, or open /dev/null instead? Or do something else? So is checking for NULL in the code below a safe way of checking whether opening... (2 Replies)
Discussion started by: gencon
2 Replies

6. OS X (Apple)

No terminal (tty) after ssh and telnet also

Hi all, we are just confused about a strange problem on one server in production (XServer, running OSXS 10.5.6). It works normal for month. Since two day everthing seems to be fine also with one exception. When we connect trough ssh we won't get a tty session. For testing purposes, we enabled... (2 Replies)
Discussion started by: Frank.Knobloch
2 Replies

7. Linux

tty terminal permissions problem

I'm hoping someone can help me out here. I'm having a problem on my Red Hat Enterprise 5 Server where my tty devices "tty" are being set to read only permissions. I need them to be set to 777 in order to write to the serial printers through a custome application. I have gone through many... (2 Replies)
Discussion started by: Netwrkengeer
2 Replies

8. Programming

sniff /dev/tty

hello all, Being root, I would like to log user activity (also multiple root activity), i don't really like history file based logging, lets assume that users have access to their .profile. I would like to write a monitoring daemon in C that would capture /dev/ttys, so I need to do a... (0 Replies)
Discussion started by: wayward
0 Replies

9. Solaris

What is /dev/tty /dev/null and /dev/console

Hi, Anyone can help My solaris 8 system has the following /dev/null , /dev/tty and /dev/console All permission are lrwxrwxrwx Can this be change to a non-world write ?? any impact ?? (12 Replies)
Discussion started by: civic2005
12 Replies
Login or Register to Ask a Question