Why is the output empty?
echo "a b c d" | read X Y Z V
echo $X
I thought it would be a.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The issue is that, in order to run the
readcommand with its input redirected from theecho, a new subshell process is spawned. This process reads the values, assigns them to the variables – and then exits; then the secondechocommand is run. To demonstrate this you can do the secondechoand thereadboth from a subshell: