0

我正在尝试在 Solaris 上使用 tee 命令将 1 个命令的输出路由到 2 个不同的流,每个流都包含多个语句。这是我编码的代码片段,但不起作用。此迭代引发有关文件意外结束的错误。如果我将 > 更改为 | 它在意外令牌附近抛出错误语法错误。

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
)

建议?

4

2 回答 2

1

" " 应该在每个替换内部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
  )
于 2011-10-21T18:01:36.627 回答
0

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

于 2011-10-21T18:01:29.803 回答