Hello,
I'm using RHEL 5.1 with bash. How to handle "read" inside while loop reading every line? Please see below:
# cat /tmp/passwd_sample
CARRJ12:qVSn4ja4mFA72,..:20021:125:JULIAN CARR:/home/everyone:/bin/bash
HERCOT01:NK/3j2ZB4ZC7Q:20022:125:TOM HERCOCK:/home/everyone:/bin/bash
NIRMALA1:35ltVGpjHq.aM:20025:125:NIRMALA KESAVAN:/home/everyone:/bin/bash
KENNEC07:GR1AlScQIfLeI:20023:125:CARL KENNEALLY:/home/everyone:/bin/bash
STANH001:VTPzaDxM1f3ps:20024:125:OWEN STANHOPE:/home/everyone:/bin/bash
#
The below works as expected:
# cat /tmp/passwd_sample |while read line
> do
> echo "${line}"
> done
CARRJ12:qVSn4ja4mFA72,..:20021:125:JULIAN CARR:/home/everyone:/bin/bash
HERCOT01:NK/3j2ZB4ZC7Q:20022:125:TOM HERCOCK:/home/everyone:/bin/bash
NIRMALA1:35ltVGpjHq.aM:20025:125:NIRMALA KESAVAN:/home/everyone:/bin/bash
KENNEC07:GR1AlScQIfLeI:20023:125:CARL KENNEALLY:/home/everyone:/bin/bash
STANH001:VTPzaDxM1f3ps:20024:125:OWEN STANHOPE:/home/everyone:/bin/bash
#
But when I use "read" it outputs without any interaction (as read is supposed to wait for our input keys) and skips few lines as shown below:
# cat /tmp/passwd_sample |while read line
> do
> echo "${line}"
> echo "Press any key to continue ...."
> read any_key
> done
CARRJ12:qVSn4ja4mFA72,..:20021:125:JULIAN CARR:/home/everyone:/bin/bash
Press any key to continue ....
NIRMALA1:35ltVGpjHq.aM:20025:125:NIRMALA KESAVAN:/home/everyone:/bin/bash
Press any key to continue ....
STANH001:VTPzaDxM1f3ps:20024:125:OWEN STANHOPE:/home/everyone:/bin/bash
Press any key to continue ....
#
Please advise on what I'm doing wrong and how to fix it, thanks!!