Ubuntu – Hide `cd something` when shopt autocd is enabled

bashcommand line

When shopt -s autocd and I navigate to any folder (for example the ~/Projects folder), I get cd ~/Projects in the terminal output and then move to the ~/Projects. How can I hide the output of what shopt just did? (the cd ~/Projects thing): the screenshot

Best Answer

This output (and a lot of other automatically-generated Bash output) is sent to the same file descriptor that set -x uses, so you could use:

exec {BASH_XTRACEFD}>/dev/null

to redirect it into /dev/null.

This appears to leak a file descriptor into all executed processes, however, which is probably undesirable. (I'm slightly surprised by this... I would have thought the BASH_XTRACEFD file descriptor would be marked close-on-exec.)

Is what i found here but i am unsure of the consequences of this redirection nor do i know how to reverse it