Silent pushd and popd in Bash Scripts
I have several shell scripts that use pushd
and popd
extensively.
These commands output the paths to stdout which may overwhelm the console output with lots of unwanted text.
Unfortunately, neither pushd
nor popd
have any silent option according to their man pages.
A simple solution is to redirect the stdout to /dev/null.
pushd $PWD > /dev/null
Is it favourable to explicitly redirect to /dev/null everytime I call pushd
/popd
in the script?
Probably not, it’s obnoxius.
Let’s 'redefine' the commands in the sript file.
Now, whenever pushd
/popd
is called in the script, their output is redirected to eternal void of /dev/null.
If you think you will never need the output of pushd
/popd
, you may define
these two functions in the .profile file.
It however affects the whole system so ponder carefully if several saved lines of code are worth the possible unforeseen consequences.