I use "cd -" to switch between folders. like:
cd /etc/ cd -
but why "cd -" will print the address(like pwd)? How can I stop it print the address?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
When a - is used as the operand, this shall be equivalent to the command:
cd "$OLDPWD" && pwd
which changes to the previous working directory and then writes its name.
So, if you don't want the printing half of the behaviour, just do the first bit yourself:
Or the tilde expansion equivalent
Often if you need this,
popd is a better albeit less portable choice.
Just redirect the stdout to black hole like this
cd - > /dev/null
The simplest way is not to use it. Run the commands in a separate shell:
(cd /etc/; ... )
This does not change the current working directory of the 'main' shell. This is typically more robust than using
OLDPWD because you can have many
cd commands here like
(cd /etc; ... ; cd /tmp; ... )