有时,由于子shell进程的原因,shell命令会出现意外行为。
我最近遇到的一个例子是,这个命令在子subshell中不能在because xargs runs the cd-command中工作:
ls | sort | tail -1 | xargs cd另一个是Makefiles中的cd doesn't work。
有没有一种方法可以可视化哪些shell/subshell/进程在(链接的)命令中做了什么?我想对他们有更好的感觉。
发布于 2021-07-09 18:54:45
也许下面的实用程序可以帮助调试管道语句:
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 _ cdhttps://stackoverflow.com/questions/68299575
复制相似问题