到2个代码块?
我尝试在 Solaris 上使用 tee 命令将 1 个命令的输出路由到 2 个不同的流,每个流包含多个语句。这是我编码的片段,但不起作用。此迭代会引发有关文件意外结束的错误。如果我改变 >至 |它会在意外标记 do 附近抛出错误语法错误。
todaydir=/some/path
baselen=${#todaydir}
grep sometext $todaydir/somefiles*
while read iline
tee
>(
# this is the first block
do ojob=${iline:$baselen+1:8}
echo 'some text here' $ojob
done > firstoutfile
)
>(
# this is the 2nd block
do ojob=${iline:$baselen+1:8}
echo 'ls -l '$todaydir'/'$ojob'*'
done > secondoutfile
)
建议?
I am trying to use the tee command on Solaris to route output of 1 command to 2 different steams each of which comprises multiple statements. Here is the snippet of what I coded, but does not work. This iteration throws errors about unexpected end of files. If I change the > to | it throws an error Syntax Error near unexpected token do.
todaydir=/some/path
baselen=${#todaydir}
grep sometext $todaydir/somefiles*
while read iline
tee
>(
# this is the first block
do ojob=${iline:$baselen+1:8}
echo 'some text here' $ojob
done > firstoutfile
)
>(
# this is the 2nd block
do ojob=${iline:$baselen+1:8}
echo 'ls -l '$todaydir'/'$ojob'*'
done > secondoutfile
)
Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“
while
”应该在每个>( ... )
替换内部开始(和结束),而不是外部。因此,我相信你想要的是:The "
while
" should begin (and end) inside each>( ... )
substitution, not outside. Thus, I believe what you want is:我认为
tee
命令不会这样做。tee
命令会将标准输入写入一个或多个文件,并将其吐回标准输出。另外,我不确定 shell 是否可以像您尝试的那样在命令管道中分叉两个子进程。您可能最好使用 Perl 之类的东西来分叉几个子进程并向每个子进程写入标准输入。I don't think the
tee
command will do that. Thetee
command will write stdin to one or more files as well as spit it back out to stdout. Plus I'm not sure the shell can fork off two sub-processes in the command pipeline like you are trying. You'd probably be better off to use something like Perl to fork off a couple of sub-process and write stdin to each.