简体   繁体   English

解析不带subshel​​l的行……如何?

[英]parse lines without subshell … how?

i need to parse a number of lines without entering a subshell 我需要解析许多行而无需进入子shell

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而不是while,但是它不会解析行,而是单词:

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. I / O重定向(包括here-documents)没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM