可视化命令的子外壳/进程

有时,由于子 shell 进程,shell 命令的行为会出乎意料。

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

ls | sort | tail -1 | xargs cd

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

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

iCMS 回答:可视化命令的子外壳/进程

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

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
本文链接:https://www.f2er.com/130242.html

大家都在问