First of all, I have little experience using Bash and I apologize for my bad English. Maybe it's obvious.
I am trying to understand why Bash drop value of the variable in this oneliner.
echo "Alpha;Beta;Gamma" | IFS=";" read First Second Third; echo $First $Second $Third
no output
But
echo "Alpha;Beta;Gamma" | (IFS=";" read First Second Third; echo $First $Second $Third)
has the right output
Alpha Beta Gamma.
I guess the read command opens a subshell and when it is close the variables lose their values.
If I am right, how to prevent it?
The goal was to separate a CSV like structure into variables.
Thanks in advice!
BR,
b
while read var ; do x=55 ; done < <(echo fred) echo "$x". But I don't understand why.lastpipeoption -- but it's not set by default). Whether that last command is awhileloop or a simple command likereaddoes not matter. As for why thedone < <(echo fred)version works, it's because that's not a pipe, so thewhileloop isn't forced into a subshell.read, but the pipeline. True,readis one to naturally appear in cases like this, but see Gilles' example ofa=0; a=1 | a=2; echo $ain their answer to thewhile readquestion.