How do I turn of "auto-echo" in bash when I 'cd'?
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Life in a Drop
--
Chapters
00:00 How Do I Turn Of &Quot;Auto-Echo&Quot; In Bash When I 'Cd'?
00:36 Accepted Answer Score 15
00:47 Answer 2 Score 4
01:08 Answer 3 Score 2
01:52 Thank you
--
Full question
https://superuser.com/questions/90535/ho...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#bash
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Life in a Drop
--
Chapters
00:00 How Do I Turn Of &Quot;Auto-Echo&Quot; In Bash When I 'Cd'?
00:36 Accepted Answer Score 15
00:47 Answer 2 Score 4
01:08 Answer 3 Score 2
01:52 Thank you
--
Full question
https://superuser.com/questions/90535/ho...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#bash
#avk47
ACCEPTED ANSWER
Score 15
The shell auto-echoes because CDPATH is defined as an environment variable. If you UNSET CDPATH the default cd behavior will appear again.
ANSWER 2
Score 4
The above answer suggesting to unset CDPATH is probably the best. However, if you want CDPATH to remain active while cd
-ing you can also use in your scripts something like:
cd /path/to/wherever > /dev/null
ANSWER 3
Score 2
Another option is to more permanently override the builtin cd
with a bash function. I've found something like this effective when placed in your ~/.profile
(or similar) file:
function cd() {
if [ -z "$*" ]; then
destination=~
else
destination=$*
fi
builtin cd "${destination}" >/dev/null && ls
}
- This preserves the use of
cd
without arguments to return to your home directory. - The
>/dev/null
is responsible for swallowing the folder name being echoed. (That echoing of the folder name is what breaks scripts that useFOO=$(cd $SOMEVAR && pwd)
to save a full path to a variable.) - And finally; as written this function performs an automatic
ls
after changing directories. (Remove the&& ls
to stop that.)