i need to parse a number of lines without entering a subshell
cat << EOF | while read -r cmd
sleep 100
sleep 110
sleep 120
EOF
do
echo $cmd
done
will result:
sleep 100
sleep 110
sleep 120
and it is working, but problem is i need the result outside subshell (be cause i need the results after), tried with for instead of while, but then it won't parse lines but words:
for cmd in `cat << EOF
sleep 100
sleep 110
sleep 120
EOF`
do
echo $cmd
done
will result:
sleep
100
sleep
110
sleep
120
so, any ideea how to do that ?
while read -r cmd; do
echo $cmd
done <<EOF
sleep 100
sleep 110
sleep 120
EOF
Pipes create a subshell. I/O redirection (including here-documents) doesn't.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.