Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This is my code:

while IFS=',' read a b c; do
     read input
     echo $input
done 3<&0 < input.csv > output.txt

I took care of input redirection by redirecting through pipeline. But still,when I run the above code, control does not stop for input.

Why?

share|improve this question

1 Answer 1

It's because your input stream is feeding both read. You're almost right, so maybe it's a typo (you just forgot to give to right FD to your second read) :

while IFS=',' read a b c; do
  read input <&3
  echo $input
done 3<&0 < input.csv >> output.txt
share|improve this answer
    
yeah I missed that, thanks again. I can read input from while loop now, however when I try the same inside a function called in while loop, it does not work. –  Menon Apr 7 at 14:38
1  
@Menon Why? You just have to replace your read input <&3 by my_function <&3 and it should work. –  apaul Apr 7 at 14:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.