Reputation: 1
I am trying to read all inputs using while loop and print them again, but for some reason doesn't read the final input.. What's going on?
#!/usr/bin/env bash
while read -r num; do
echo $num
done
4
1
2
9
8
4
1
2
9
# Last input is missing :(
4
1
2
9
8
Upvotes: 0
Views: 68
Reputation: 5214
You may forget to add a new line at the end of input.
4
1
2
9
8 # A new line expected, after the character "8".
Or we say, 4\n1\n2\n9\n8\n
.
Otherwise, the last line won't be "enter"ed into the script / program.
Upvotes: 1