Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Tweeted twitter.com/StackUnix/status/1025577854506094592
added 21 characters in body; edited title
Source Link
slm
  • 380k
  • 127
  • 793
  • 897

use Use read as a prompt inside a while loop driven by read?

I have a usecaseuse case where I need to read in multiple variables at the start of each iteration and read in an input from the user into the loop.

Possible paths to solution which I do not know how to explore --

  1. For assignment use another filehandle instead of stdin

    For assignment use another filehandle instead of stdin

  2. Use a for loop instead of ... | while read ... ... I do not know how to assign multiple variables inside a for loop

    Use a for loop instead of ... | while read ... ... I do not know how to assign multiple variables inside a for loop

     echo -e "1 2 3\n4 5 6" |\
     while read a b c; 
     do 
       echo "$a -> $b -> $c";
       echo "Enter a number:";
       read d ;
       echo "This number is $d" ; 
     done
    
    echo -e "1 2 3\n4 5 6" |\
    while read a b c; 
    do 
      echo "$a -> $b -> $c";
      echo "Enter a number:";
      read d ;
      echo "This number is $d" ; 
    done

use read as a prompt inside a while loop driven by read

I have a usecase where I need to read in multiple variables at the start of each iteration and read in an input from the user into the loop.

Possible paths to solution which I do not know how to explore --

  1. For assignment use another filehandle instead of stdin
  2. Use a for loop instead of ... | while read ... ... I do not know how to assign multiple variables inside a for loop
    echo -e "1 2 3\n4 5 6" |\
    while read a b c; 
    do 
      echo "$a -> $b -> $c";
      echo "Enter a number:";
      read d ;
      echo "This number is $d" ; 
    done

Use read as a prompt inside a while loop driven by read?

I have a use case where I need to read in multiple variables at the start of each iteration and read in an input from the user into the loop.

Possible paths to solution which I do not know how to explore --

  1. For assignment use another filehandle instead of stdin

  2. Use a for loop instead of ... | while read ... ... I do not know how to assign multiple variables inside a for loop

     echo -e "1 2 3\n4 5 6" |\
     while read a b c; 
     do 
       echo "$a -> $b -> $c";
       echo "Enter a number:";
       read d ;
       echo "This number is $d" ; 
     done
    
Source Link
Debanjan Basu
  • 383
  • 1
  • 2
  • 6

use read as a prompt inside a while loop driven by read

I have a usecase where I need to read in multiple variables at the start of each iteration and read in an input from the user into the loop.

Possible paths to solution which I do not know how to explore --

  1. For assignment use another filehandle instead of stdin
  2. Use a for loop instead of ... | while read ... ... I do not know how to assign multiple variables inside a for loop
    echo -e "1 2 3\n4 5 6" |\
    while read a b c; 
    do 
      echo "$a -> $b -> $c";
      echo "Enter a number:";
      read d ;
      echo "This number is $d" ; 
    done