Can anyone explain this behavior? Running:
#!/bin/sh
echo \"hello world\" | read var1 var2
echo $var1
echo $var2
results in nothing being o
This has already been answered correctly, but the solution has not been stated yet. Use ksh, not bash. Compare:
$ echo 'echo "hello world" | read var1 var2
echo $var1
echo $var2' | bash -s
To:
$ echo 'echo "hello world" | read var1 var2
echo $var1
echo $var2' | ksh -s
hello
world
ksh is a superior programming shell because of little niceties like this. (bash is the better interactive shell, in my opinion.)