Shell read command is not waiting for user input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell read command is not waiting for user input
# 1  
Old 05-11-2016
Shell read command is not waiting for user input

Hi,

i am working on one automation , for that i have writing one shell program that take user input in "while read line" block. but read command is taking value that is readed by While block.

Code:
while read line; do
command 1;
command 2

echo -n "Do you want to continute > "
read rsp
echo "You entered: $rsp"
if [ $rsp =='Y' ]; then
echo "Going to next step.."
fi
done<PART_TAB.txt

After running this shell script ,
Code:
-n Do you want to continute >
You entered: MSC:MSC_NET_RESOURCE_AVAIL
./Defrag_Exec.sh[130]: test: argument expected

In output,MSC:MSC_NET_RESOURCE_AVAIL is the vlaue that is readed by while block from PART_TAB.txt file.Please let me know where the problem is

thanks
# 2  
Old 05-11-2016
Both reads take input from stdin, which is redirected from your .txt file. One option (taken from the links at the bottom of this page) would be to to address the terminal directly:
Code:
read rsp < /dev/tty

# 3  
Old 05-12-2016
Thanks Rudi, you solved my issue.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to read user input

I am creating a bash that uses perl . The below code closes before the input is entered. If I run the perl as a .pl it is fine. What am I doing wrong? Thank you :). #!/bin/bash cd 'C:\Users\cmccabe\Desktop\wget' wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv print... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

3. Shell Programming and Scripting

read command not waiting

Dear All, read command not waiting for my input, please suggest. code: while read line do echo "$line " | grep -i .par$ if ; then cd ../par echo " Do you want to proceed" read else cd ../sql read fi done <inp.txt Its not asking me any input? (2 Replies)
Discussion started by: mahendra singh
2 Replies

4. Shell Programming and Scripting

Solaris- Read command from user input

I need to write a bourne shell script (solaris 10) that accepts input from the user. The input will be a command- any command like ls/ pwd/ mv etc. After the input is read, the shell must execute the command supplied by the user. I know we use read to play with user inputs. Just not sure how to... (2 Replies)
Discussion started by: PDManc
2 Replies

5. Shell Programming and Scripting

SQL PLUS Command 'ACCEPT' is not waiting for user input with sh shell script

Dear All, The sqlplus 'Accept' command is not waiting for user input when I include the command within a shell script. Note: The 'Accept' command is working fine if I execute it in a SQLPLUS Prompt. Please fins the below sample script which i tried. SCRIPT: -------- #!... (4 Replies)
Discussion started by: little_wonder
4 Replies

6. Shell Programming and Scripting

Manipulating input into the shell "read" command

Hi All I have a migration program that creates directories based on dates, e.g 20090714 20090812 etc.. Based on their requirements, the user will select the directory they want to perform an action on. Currently, this is a snippet of the code I use no_of_versions=`ls | wc -l` if... (2 Replies)
Discussion started by: kingpin2502
2 Replies

7. Shell Programming and Scripting

How can I send the input of a read line command through a shell script

Hi All, I wish to automate the unix command 'su' through a shell script. I would like to pass the content of a file as password to 'su' command. My script is as below, #! /bin/sh su userA while read line do rpm -ivh $line done < pwd.txt where pwd.txt contains the password of... (6 Replies)
Discussion started by: little_wonder
6 Replies

8. UNIX for Dummies Questions & Answers

getline to read input from a user

Hi, The gcc compiler has warned about using gets(), so I've been trying my hand at getline. Problem is that I've been able to read from a file, but what I really need is to read from a user's input. I want to use getline like a scanf() command, but I can't figure what to substitute for the fp... (6 Replies)
Discussion started by: sdsd
6 Replies

9. Programming

Detecting if command is waiting for input

Hi, After doing a fork and executing a shell, we execute (third party) commands which are essentially non-interactive. But some of them ask for input, under some (unforeseeable) circumstances. When this happens we go on waiting for output. Their is timeout, of course, but we don't seem to know... (5 Replies)
Discussion started by: slash_blog
5 Replies

10. Shell Programming and Scripting

read-waiting for user response

Would there be any reason for why a 'read ans' would not wait for a user's response (i.e user has to hit a key to continue)? I know for sure that it is doing everything else in that part of my 'if' statement but it doesn't wait for me to hit a key before continuing. The strange thing is that... (4 Replies)
Discussion started by: giannicello
4 Replies
Login or Register to Ask a Question