0

I am not able to understand why the read command is not working without the while loop as shown in the code below. I referred this Using “while read…” in a linux script question where the answer also mentioned that since the input is a single line

This is to say that having a while loop here is not really accomplishing anything.

 55 echo "Some sample text" | read var1 var2
 56
 57 echo "Var1: ${var1}"
 58 echo "Var2: ${var2}"
 59
 60 echo "----------------------------"
 61
 62
 63 echo "Some sample text" | while read v1 v2
 64 do
 65        echo "Var1: ${v1}"
 66        echo "Var2: ${v2}"
 67 done
 68
 69 echo "----------------------------"

Output:

Var1:
Var2:
----------------------------
Var1: Some
Var2: sample text
----------------------------
Manav Saxena
  • 453
  • 2
  • 8
  • 21

0 Answers0