I have a program that outputs several lines. I want to assign each line to a different variable. I have tried to pipe the output to a block:
my_program | {
read -r foo
read -r bar
read -r baz
}
It seems that I can only access those variables inside the block but I don't want to put everything inside the block.
I have also tried to use the -d option with a character that is unlikely to show up in the output as it's argument.
IFS=$'\n' read -r -d$'\a' foo bar baz < <(my_program)
It seems to work except that if there are more than 3 lines, the variable 'baz' get the third line and all the extra lines. It's not really a problem since I know the exact number of lines that my program is going to output.
I wonder if there is a better way to do this.