ksh while read issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh while read issue
# 1  
Old 07-24-2015
ksh while read issue

Hello,
I have used a chunk of ksh script similar to this in many places without any issue:
Code:
    
while :
    do
        print;
        read OPTION?"Enter a number (q to quit): "
        expr ${OPTION} + 1 >/dev/null 2>&1
        CHECKVAL=$?

        if [ "${OPTION#*[Qq]}" != ${OPTION} ]; then
            return
        fi
    done

Now I am trying to cycle this for each record in a single column text file and when I enclose it in the "while read":
Code:
while read SRV
do
    while :
    do
        print;
        read OPTION?"Enter a number (q to quit): "
        expr ${OPTION} + 1 >/dev/null 2>&1
        CHECKVAL=$?

        if [ "${OPTION#*[Qq]}" != ${OPTION} ]; then
            return
        fi
    done
done < singlecolumnfile.txt

it no longer stops for the read OPTION in the center "while" and gives the error:
Quote:
./trial.ksh[11]: test: 0403-004 Specify a parameter with this command.
What is causing this behavior?

Thanks for any insight.
# 2  
Old 07-24-2015
you're reading the file content AND prompting from the same 'stream' - stdin.
You need to split that into 2 streams:
Code:
#!/bin/ksh

exec 3< singlecolumnfile.txt

while read -u3 SRV
....
done

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 07-24-2015
Makes perfect sense; thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh to read input until QUI

Hello all I'm looking to write a simple script (ksh/sh/bsh) to read user input and write it to a file (adding each time) until the user enters QUIT at which point I'm hoping to ask some more questions. Any help much apprecited (2 Replies)
Discussion started by: Grueben
2 Replies

2. Shell Programming and Scripting

While read -a line not working in ksh

while read -a line; this is not working in ksh. what is the equivalent of this in ksh. read: -a: unknown option (2 Replies)
Discussion started by: archana25
2 Replies

3. Shell Programming and Scripting

-z in ksh issue

Hi, Can any body please tell me what does -z do in ksh? I need to understand what does below code do? FILE_LIST is an array which store multiple number of files... if } ]]; then echo "EVDO file not found fi I hope I'm clear on my query (3 Replies)
Discussion started by: annybase
3 Replies

4. UNIX for Dummies Questions & Answers

Question with read command in ksh

Hi, I was writing a script to accept input using read. When I put !#/usr/bin/ksh in the beginning of the script, it accepts only 258 characters. And I remove it, it accepts more. I'm wondering what the difference is. Thanks in advance, (7 Replies)
Discussion started by: swmk18
7 Replies

5. Shell Programming and Scripting

Read from Log file in Ksh

I have a log file like.. IMPORT from /dataserver/ftp/bits/mdr/mdr_data_discon.dat OF DEL ..... Number of rows read = 1376 Number of rows skipped = 0 Number of rows inserted = 1374 Number of rows updated = 0 Number of rows rejected = 2 Number of rows... (4 Replies)
Discussion started by: ramse8pc
4 Replies

6. UNIX for Dummies Questions & Answers

simple way to read an array in ksh

hi, I'm a newbie to shell scripting. I wanted to initialise an array using basic for loop and read it. Then i want to print it as a .CSV file.. Any help would me much appreciated.. (1 Reply)
Discussion started by: pravsripad
1 Replies

7. Shell Programming and Scripting

read values from ps -ef into variables in ksh?

Hi, I want to get the first two items returned by ps -ef into two variables? Can anyone please help Thanks (8 Replies)
Discussion started by: JamesByars
8 Replies

8. Shell Programming and Scripting

read from console in ksh

I am stuck with a problem while reading data from a file.. while do read line #do some operations and if some condition is satisfied, ask the user to enter his choice. # using the choice continue operations. done < fileBeingRead.txt The... (4 Replies)
Discussion started by: ajaykumarns
4 Replies

9. Shell Programming and Scripting

is there any way to read a line twice in KSH

Hi All, Is there any way to read the previous line in file reading ? or is there any way to read a line twice in KSH ? thanks in advance !! Srini (6 Replies)
Discussion started by: Srini75
6 Replies

10. Shell Programming and Scripting

ksh read timeout

any idea on how to timeout the read statement for ksh? for bash u can use read -t option -t timeout Cause read to time out and return failure if a complete line of input is not read within timeout seconds. This option has ... (2 Replies)
Discussion started by: ashterix
2 Replies
Login or Register to Ask a Question