加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

>(tee -a …)命令bash

发布时间:2020-12-16 01:48:45 所属栏目:安全 来源:网络整理
导读:我有这个运行 Scala测试代码的bash代码: scripts=(Hello.scala)for script in "${scripts[@]}"; do echo scala "${script}" scala -nocompdaemon "${script}" (tee -a _testoutput.txt) 2 (tee -a _testerrors.txt 2)done 如何解释(tee -a _testoutput.tx
我有这个运行 Scala测试代码的bash代码:

scripts=(
Hello.scala
)

for script in "${scripts[@]}"; do
    echo scala "${script}"
    scala -nocompdaemon "${script}" > >(tee -a _testoutput.txt) 
        2> >(tee -a _testerrors.txt >&2)
done

如何解释>(tee -a _testoutput.txt)?我通常使用| (管道)使用tee,使用这个表达式有什么区别?

解决方法

在这种情况下,我相信> >(tee -a _testoutput.txt)和| tee -a _testoutput.txt表现相同.

由于没有stderr管道,因此显然需要标准错误版本.

管道版本和Process Substitution(>(…))版本之间的另一个主要区别是子shell发生的位置.

例如,如果>(…)在整个循环中并且您需要在循环中设置的变量在循环之外持久存在,则无法使用管道版本执行此操作(有关此内容的更多信息,请参阅BashFAQ 24) .

CharlesDuffy正确指出的另一个区别是,管道会影响管道的退出状态(默认情况下,您会在管道中获得最终命令的退出状态,但设置-o pipefail会更改,并且bash PIPESTATUS数组会保留所有退出状态).另一方面,进程替换不会影响退出状态.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读