到2个代码块?

发布于 2024-12-11 18:58:03 字数 510 浏览 0 评论 0原文

我尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧伤慢歌 2024-12-18 18:58:03

while”应该在每个 >( ... ) 替换内部开始(和结束),而不是外部。因此,我相信你想要的是:

todaydir=/some/path
baselen=${#todaydir}

grep sometext $todaydir/somefiles* | tee >(
   # this is the first block
   while read iline
   do ojob=${iline:$baselen+1:8}
      echo 'some text here' $ojob
   done  > firstoutfile
  ) >(
   # this is the 2nd block
   while read iline
   do ojob=${iline:$baselen+1:8}
      echo 'ls -l '$todaydir'/'$ojob'*'
   done  > secondoutfile
  )

The "while" should begin (and end) inside each >( ... ) substitution, not outside. Thus, I believe what you want is:

todaydir=/some/path
baselen=${#todaydir}

grep sometext $todaydir/somefiles* | tee >(
   # this is the first block
   while read iline
   do ojob=${iline:$baselen+1:8}
      echo 'some text here' $ojob
   done  > firstoutfile
  ) >(
   # this is the 2nd block
   while read iline
   do ojob=${iline:$baselen+1:8}
      echo 'ls -l '$todaydir'/'$ojob'*'
   done  > secondoutfile
  )
伴梦长久 2024-12-18 18:58:03

我认为 tee 命令不会这样做。 tee 命令会将标准输入写入一个或多个文件,并将其吐回标准输出。另外,我不确定 shell 是否可以像您尝试的那样在命令管道中分叉两个子进程。您可能最好使用 Perl 之类的东西来分叉几个子进程并向每个子进程写入标准输入。

I don't think the tee command will do that. The tee 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文