【问题标题】:Visualize subshells/processes for command可视化命令的子shell/进程
【发布时间】:2021-09-18 19:10:40
【问题描述】:

有时由于子shell 进程,shell 命令会出现意外行为。

我最近遇到的一个例子是,这个命令在子shell 中不起作用because xargs runs the cd-command

ls | sort | tail -1 | xargs cd

另一个是 Makefiles 中的 cd doesn't work

有没有办法可视化哪些外壳/子外壳/进程在(链式)命令中执行什么操作?我想对他们有更好的感觉。

【问题讨论】:

    标签: shell process cd subshell


    【解决方案1】:

    也许以下实用程序可以帮助调试管道语句:

    function _() {
      local code=0
      "$@" || code=$? > >(tee -a "$1".out) 2> >(tee -a "$1".err >&2)
      echo Exited with "$code" >> "$1".out
    }
    

    用法:

    _ ls | _ sort | _ tail -1 | xargs _ cd
    

    【讨论】:

      猜你喜欢
      • 2017-06-09
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多