Getting user input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting user input
# 1  
Old 02-16-2007
Question Getting user input

I am trying to create a shell (ksh) which has two "read" commands, one which reads a line from a file and another which is inside a loop that reads user input from a keyboard. However, the "read" command inside the loop uses the input from the file and it does not get the user input from keyboard.

Code:
$ more readtest.ksh
#!/bin/ksh

echo "AAA\nBBB\nCCC" > file

while read line
do

     echo "Enter word:"
     read word
     echo "$line $word"

done < file

Could someone please tell me how to fix the shell above to get user input from keyboard?

Any help will be appreciated.

Steve
# 2  
Old 02-16-2007
Code:
read word < /dev/tty

# 3  
Old 02-16-2007
Code:
#!/bin/ksh

echo "AAA\nBBB\nCCC" > file

while read line
do

     echo "Enter word:"
     read word <&1
     echo "$line $word"

done < file

# 4  
Old 02-16-2007
Thanks anbu23 and matrixmadhan!

It worked!

Cheers
Steve
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Controlling user input

I'm trying to use a bash script for a psych experiment that involves listening to sound files and responding. If I have something like the code below, how can I make sure that a key press is assigned to RESPONSE only after the second echo statement? for i in 1 2 3; do echo "Ready?" sleep 2 ... (10 Replies)
Discussion started by: darwin_886
10 Replies

2. Shell Programming and Scripting

User input and run awk using the input

I am trying to allow a user to enter in text and then store that text in a variable $gene to run in an awk command in which those values are used to run some calculations. I am getting syntax errors however, when I try. Thank you :). The awk runs great if it is a pre-defined file that is used,... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. UNIX for Dummies Questions & Answers

Clumsy user input

The (longer) script that I am working on does something like this: #!/bin/bash while true do clear sleep 1 shuf -i1-2 -n1 sleep .1 clear echo "Press 1 if you saw a 1. Press 2 if you saw a 2." read -s -n1 RESPONSE done If the user accidentally presses two... (1 Reply)
Discussion started by: darwin_886
1 Replies

4. Shell Programming and Scripting

How to validate user's input..?

$Input_filename=$ARGV; if (!-d $Input_filename && ! -e $Input_filename) { print "USAGE: Please enter '$ABCD/def/dsed.txt' as an arguement \n"; exit; } 1. Input Is suppose to be something like "$ABCD/def/dsed.txt". if the input is wrong the script should throw an ERROR message.... (2 Replies)
Discussion started by: Rashid Khan
2 Replies

5. Shell Programming and Scripting

How-To Trim user input

Hi, The user inputs either "/tmp/bea" or "/tmp/bea/". Regardless my script should extract and store in a variable the last directory in the user input path. Desired output: "bea" Please help. (6 Replies)
Discussion started by: mohtashims
6 Replies

6. Shell Programming and Scripting

Check user input

Hi, I need my script to check if the user enters 3 values if not 5 values to my script and alert if the input has any other number of values. for example: ./myscript.sh 22 56 3221 - > correct ./myscript.sh 22 56 3221 45 777 -> correct ./myscript.sh 22 56 3221 45 -> incorrect Please... (6 Replies)
Discussion started by: mohtashims
6 Replies

7. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

8. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

9. UNIX for Dummies Questions & Answers

accept user input?

how would i accept user input from the keyboard? (2 Replies)
Discussion started by: JamieMurry
2 Replies

10. Shell Programming and Scripting

user input date

I am trying write a script that takes user input date in the format "Mar 18". If it is march1 it is like "Mar 1" . Once i take this input i will go back to my log files and search for any failed transactions recorded that day. If there are then i will send it to a file and mail it. I am... (10 Replies)
Discussion started by: gundu
10 Replies
Login or Register to Ask a Question