6

I have a script composed of a while loop with an echo in it:

while my_condition
do
echo [my_output]
done

How can I gather the output in a single pipe?

I would need to use column after the output pipe'

13

No need to "transform" anything, just put the pipe after the loop:

while my_condition
do
    echo [my_output]
done | column

For example:

$ while read num; do 
    echo "$num" 
  done < <(seq 1 100) | column
1   11  21  31  41  51  61  71  81  91
2   12  22  32  42  52  62  72  82  92
3   13  23  33  43  53  63  73  83  93
4   14  24  34  44  54  64  74  84  94
5   15  25  35  45  55  65  75  85  95
6   16  26  36  46  56  66  76  86  96
7   17  27  37  47  57  67  77  87  97
8   18  28  38  48  58  68  78  88  98
9   19  29  39  49  59  69  79  89  99
10  20  30  40  50  60  70  80  90  100
  • You could even use a pipe to “feed” the output of seq to the loop. No need for FIFO redirection. – David Foerster Oct 21 '16 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.