shell script problem: does not work on the terminal, but works in a script

Posted by jrharshath on Stack Overflow See other posts from Stack Overflow or by jrharshath
Published on 2010-03-12T19:16:19Z Indexed on 2010/03/12 19:27 UTC
Read the original article Hit count: 285

Filed under:

Hi,

I was playing with shell scripting, when a strange thing happened. I need someone to explain it.

I have a file 'infile', contents:

line one
line2
third line
last

a test script test.sh, contents:

read var1
echo $var1

i executed:

cat infile | ./test.sh

output was

line one

Then I did:

cat infile | read var1
echo $var1

Result: a blank line.

I even tried

cat infile | read var1; echo $var1;

same result.

why does this happen?

© Stack Overflow or respective owner

Related posts about shell-scripting