My bash shell will no longer change directory with cd. I noticed it earlier when working and found that any new shells I opened (terminal or xterm etc) would be stuck in the home directory and could not get out (already open terminals continued to work fine).

[~]$ pwd
[~]$ cd /
[~]$ cd Documents/
[~]$ pwd
[~]$ type cd
cd is a shell builtin
[~]$ alias
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

I thought it must be some weirdness I didn't have time to deal with such as a handler out of memory (having checked that cd wasn't aliased and using the builtin version).

So I (yes, I know) rebooted the machine.

Fresh boot, exactly the same problem.

CSH on the other hand works fine, so immediately after the snippet above:

[~]$ csh
[~]$ cd /
[/]$ pwd
[/]$ cd ~/Documents/
[~/Documents]$ pwd

I haven't installed anything new or performed any updates in the last few days and it was working fine until late this evening.

Ideas/assistance/HELP much appreciated!

** UPDATE **

So digging around I found this line in .bashrc

export PROMPT_COMMAND="cd"

If I unset PROMPT_COMMAND then everything works as normal.

But... WTF. I didn't put this line in the .bashrc and everything was working perfectly until tonight. Should I just comment it out, manually unset it, or just burn the computer as a witch?

  • OS is CentOS 6.3 Final, Kernel is 2.6.32-279.11.1.el6.x86_64, command-line expansion through tab if I put in a full directory name and type/more etc again if I put in a FQ file path work fine. If that helps. – Dave C Mar 5 '13 at 22:55
  • 3
    If something on your system recently changed, and you are the only user and you didn't make that change, then perhaps your system has been compromised? – Zoredache Mar 5 '13 at 23:10

Setting PROMPT_COMMAND to cd is a pretty common prank, if you didn't set it, and you're the only user, then yes, you've been compromised.

If friends have access though, this is a prank I've seen numerous times, talk with them.

  • 6
    Or if you're in an environment where you might have left your terminal unlocked. It depends on the corporate culture, but since unlocked terminals are a frowned upon practice, pranking between sysadmins is fairly common. – Andrew B Mar 6 '13 at 0:22
  • 4
    I think I've been pranked. +1 to my lab colleagues for a Linux prank. -1 to me for leaving the screen unlocked. Don't think I've been compromised, well at least I hope not - everything else looks well. Thanks to all for your answers. – Dave C Mar 6 '13 at 15:59
  • 1
    Technically, this is still a compromise, even if it was done "for fun". Depending on who you are and where you are, it could lead to you and/or your colleagues getting told off or worse, or it might be your responsibility to report the compromise to IT staff (by law). – Kusalananda Aug 18 '19 at 7:08

If PROMPT_COMMAND environment variable is set, the value is executed as a command prior to issuing each primary prompt. In other words, the contents of this variable are executed as a regular Bash command just before Bash displays a prompt:

[vivek@vivek-desktop man]$ PROMPT_COMMAND="echo Yahooo"
[vivek@vivek-desktop man]$ date
Tue Oct 20 23:50:01 IST 2009


cd without arguments returns to the home directory (handy!).

.bashrc gets executed when spawning each shell, that's why the old terminals were unaffected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.