I observe a behavior that I don't undrestand and would like someone to shed some light on it.
I have two scripts, both read from STDIN.
Reading a sequence of numbers from keyboard ( 1 enter 2 enter 3 enter ... )
Script A prints "x" everytime
#!/bin/bash
while read LINE
do
echo "x" # this happens everytime
echo $LINE # this is the only different line
done
output:
1
x
1
2
x
2
3
x
3
4
x
4
5
x
5
Script B prints "x" only the first time it reads LINE
#!/bin/bash
while read LINE
do
echo "x" # this happens only the first time
awk '{print $LINE}' # this is the only different line
done
output:
1
x
2
2
3
3
4
4
5
5
Can someone explain this ?