Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am writing a shell script (it happens to be on Solaris in KSH) which recieves a file from standard input -- in other words, when I run the script, I do this:
cat text_file | ./my_script
In the script, I send the input to an output file ( "cat > out_file"). Later in the script, I try to prompt for input from the user. However, I've tried both a "read" and a "ckyorn" to get input from the user, but the script does not wait for input from the user. It just goes on to the next line of the script and uses nulls for the answer. Any thoughts on how I can force the script to read new input from stdin? Thanks!

Jo,
An exec command will switch stdin from the pipe to the terminal, as shown below. But note that less-than-signs get special handling by this web site, so in the following code, on the first exec line, the X should actually be a less-than-sign:cat > out_file
exec X /dev/tty
echo 'enter ans: \c'
read ans
echo "your answer was $ans"Also, when I want my ALL script output to go to a log file, I can do that inside the script with:
exec > /mydir/mylogfile
and with the above in effect, individual commands can still be forced to the screen, such as:
echo 'Enter answer: \c' > /dev/tty

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |