SH script problem with read


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SH script problem with read
# 1  
Old 10-05-2005
SH script problem with read

Hi, I'm doing a script that reads lines from a file and then copy them to another file, if the user wants it.
But I'having problems to get the user selection because when I do the read to ask the user, the script reads the next line of the file.
The script looks like this:
#!/bin/sh
#
for filename
do
while read line
do
grep -q $line $word_file
if [ "$?" = "1" ]
then
echo "Insert word in file2? (Y/N)"
read question
if [ "$question" = "y" ]
then
Append line to file2
fi
fi
done < $filename
done

Does anyone knows how to do this? I would like to maintain programming in SH shell.

Thanks in advance!
# 2  
Old 10-05-2005
Not sure I followed that. But if I did...

read question < /dev/tty
# 3  
Old 10-05-2005
Smilie
It worked!
Thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Read -p problem

Hi, :) I tried to make of "line returns" with "\n" : read -p $'Do you really want append this line in '$CONFIG_FILE''\n'IP CLIENT: '$IP_INPUT' - PATH: '$PATH_INPUT''\n'y/n ?:' CONFIRM_INPUT But it didn't work, please anyone have an idea? :b: (2 Replies)
Discussion started by: Arnaudh78
2 Replies

2. Shell Programming and Scripting

Read format problem in ksh script

I have ksh script reading file like while read -r line do echo $line sleep 1 #process_file $line done<$file_nm I want to write this line to another file after some manuplation.Put $line giving me line after changing line format(space removed).Please help me how can i read line by... (3 Replies)
Discussion started by: Mandeep
3 Replies

3. Shell Programming and Scripting

Problem with read line

Hi everybody, I am new to shell script. Please help me with this problem. I have a file test.txt with the content like this: I have a shell script test.sh like this #!/bin/sh while read line do echo $line >> out.txt done < test.txt out.txt is expected to have the same content... (10 Replies)
Discussion started by: Dark2Bright
10 Replies

4. Shell Programming and Scripting

Problem to read archive

Dear all, I have this archive: cat file.txt archive test 02 sequence 03 02length 52 archive test 02 sequence 04 02length 52 archive test 02 sequence 05 02length 52 teste arquivo 06 sequencia 08 06 length 54 teste arquivo 06 sequencia 09 ... (8 Replies)
Discussion started by: cewa67
8 Replies

5. Shell Programming and Scripting

problem with read command

Hi Guys, I am just trying to read data from a file. The command i tried worked well with AIX server. But in SunOS, it is not reading. cat log.out |sed -n '4,4p'| read value; + sed -n 4,4p + cat log.out + read value echo $value; + echo This is the log of running the script. ... (13 Replies)
Discussion started by: mac4rfree
13 Replies

6. Shell Programming and Scripting

While Read problem

Hello, I have this simple script while read name do ssh $name "hostname > /tmp/$name.txt" ssh $name "/opt/ignite/bin/print_manifest | grep Main >> /tmp/$name.txt" ssh $name "getconf MACHINE_SERIAL >> /tmp/$name.txt" ssh $name "ioscan -kfnC processor | grep processor | wc -l >>... (3 Replies)
Discussion started by: Andyp2704
3 Replies

7. Shell Programming and Scripting

Very Challenging Problem. Please read fully.

Hi, This is the Third thread i'm putting here for the same problem. :( Actually, i'm trying a script like this.. but its taking a long time.. about 3 days to complete fully.. #!/bin/ksh if then exit 1 fi while read i do while read j do field7=`echo $j|cut -d "|"... (12 Replies)
Discussion started by: RRVARMA
12 Replies

8. Programming

Problem in read() from a pipe

Hi, Can any one please help me with this. Am struggling hard to get a solution. I am doing telnet through a C program and getting the stdout file descriptor of the remote machine to pipe. read() function is getting data, But whenl it receives SOH character ie. ^A ( Start of heading = Console... (2 Replies)
Discussion started by: JDS
2 Replies

9. Shell Programming and Scripting

Problem with read in sh

I've discovered a very annoying problem in sh: echo -en "one\ntwo\nthree" | while read VALUE do echo "${VALUE}" done This will print one and two, but not three. The last line is IGNORED because it lacks a newline. This makes it hard to use sh for things like CGI scripting; you have... (6 Replies)
Discussion started by: Corona688
6 Replies

10. Shell Programming and Scripting

read after pipe problem OSX10.4

I use read often in scripts to filter the right part into a variable like: $ print "abc cde efg" | read k l ; print "k=$k, l=$l" k=, l= This works on linux and unix versions I work with. On OSX 10.4 this doesn't work. I found a workaround but would like to know why the original line... (5 Replies)
Discussion started by: relyveld
5 Replies
Login or Register to Ask a Question