Don't display pushd/popd stack across several bash scripts (quiet pushd/popd)

BashOutputBuilt In

Bash Problem Overview


Each time I use pushd or popd, it print the stack to standard output. How not to do so?

I don't want to do pushd > /dev/null each time because I have a lot of scripts calling each other.

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.

Bash Solutions


Solution 1 - Bash

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.

Solution 2 - Bash

In zsh you can setopt PUSHDSILENT. Put this in your ~/.zshrc.

Solution 3 - Bash

In your .profile file (what ever it is called in your system) add:

pushd () {
    command pushd "$@" > /dev/null
}

popd () {
    command popd "$@" > /dev/null
}

export pushd popd

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbemugView Question on Stackoverflow
Solution 1 - BashchepnerView Answer on Stackoverflow
Solution 2 - BashMichael DeardeuffView Answer on Stackoverflow
Solution 3 - BashbozonView Answer on Stackoverflow