不要在多个 bash 脚本中显示 pushd/popd 堆栈(安静的 pushd/popd)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25288194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Don't display pushd/popd stack across several bash scripts (quiet pushd/popd)
提问by bemug
Each time I use pushd or popd, it print the stack to standard output. How not to do so?
每次我使用 pushd 或 popd 时,它都会将堆栈打印到标准输出。不这样做怎么办?
I don't want to do pushd > /dev/null
each time because I have a lot of scripts calling each other.
我不想pushd > /dev/null
每次都这样做,因为我有很多脚本互相调用。
Maybe a nice override will do it, but I'll need to override these builtins only in my scripts, and then restore the correct behavior.
也许一个很好的覆盖可以做到,但我只需要在我的脚本中覆盖这些内置函数,然后恢复正确的行为。
回答by chepner
You could add
你可以添加
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd "$@" > /dev/null
}
to the top of each script. This is probably the minimum amount of work it will take to solve your problem.
到每个脚本的顶部。这可能是解决您的问题所需的最少工作量。
回答by Michael Deardeuff
In zsh you can setopt PUSHDSILENT
. Put this in your ~/.zshrc
.
在 zsh 中你可以setopt PUSHDSILENT
。把它放在你的~/.zshrc
.
回答by bozon
In your .profile file (what ever it is called in your system) add:
在您的 .profile 文件(在您的系统中称为什么)中添加:
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd "$@" > /dev/null
}
export pushd popd