0

I’m on Mac OS X 10.10. All of the sudden, my “Terminal” started running a command whenever I open a new tab. This is frustrating because I'm used to being able to type immediately when opening a tab and having the command execute as I typed it.

For example, before this problem I could hit cmd+T and then immediately type bin/rails c and when the tab was ready, bin/rails c would be on the command line and I could just hit enter. Now, this is what happens:

bin/lserman-5:test lserman$ bin/cd /workspace/test/app/helpers
-bash: bin/cd: No such file or directory
lserman-5:test lserman$ rails c

The command that is run is cd /workspace/test/app/helpers, which gets executed when I’m in the middle of typing bin/rails c. cd is also a pain because the terminal switches to a different directory when I’m used to having it open the tab in the same place the previous tab was at. For example, this is what I get when I just hit cmd+T without typing anything immediately:

lserman-5:test lserman$ cd /workspace/test/app/helpers
lserman-5:helpers lserman$ 

The actual command seems to change every couple of days. I have no idea what causes it. If I remember correctly, it seems that it's always some form of cd. I’ve looked in .profile, .bash_profile, and .bashrc and I see nothing out of the ordinary. What else can cause this to happen?

The contents of /etc/profile:

# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi

The contents of /etc/bashrc:

# System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then
   return
fi

PS1='\h:\W \u\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize
# Tell the terminal about the working directory at each prompt.
if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then
    update_terminal_cwd() {
        # Identify the directory using a "file:" scheme URL,
        # including the host name to disambiguate local vs.
        # remote connections. Percent-escape spaces.
    local SEARCH=' '
    local REPLACE='%20'
    local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
    printf '\e]7;%s\a' "$PWD_URL"
    }
    PROMPT_COMMAND="update_terminal_cwd; $PROMPT_COMMAND"
fi
  • Have you installed anything recently? I'm not a Mac person but Mac is UNIXy and there will be something in your profile file. – Julian Knight Mar 25 '15 at 17:12
  • There are several settings in Terminal.app's preferences that let you specify what commands are run when you open a new window. Have you checked those? – Spiff Mar 25 '15 at 18:23
  • @JulianKnight not that I know of, expand on profile file? – Logan Serman Mar 25 '15 at 19:28
  • @Spiff in Terminal I have New tabs open with: Same Profile, Same Working Directory. That sounds like what I want, it's just not happening – Logan Serman Mar 25 '15 at 19:29
  • In Linux you use BASH normally as the terminal env. That runs a global and a user profile script and a global and user bash.rc and/or .bash script when starting the terminal. – Julian Knight Mar 25 '15 at 21:47
0

This is frustrating but shouldn’t be too difficult to debug. Checking /etc/profile and /etc/bash.rc is a bit too deep and excessive. The first places I would check are in the user-specific shell environment files that get loaded each time a new window is opened: ~/.bash_profile, ~/.bash_login and ~/.profile.

My guess is some command junk was appended to the end of at least one of those files. And all those files do is define your local Bash shell environment which is what you see when you first open a “Terminal” window or open a new tab in “Terminal.”

Look in each file like this; I’m using nano in this example but feel free to use whatever plain-text editor you prefer

nano  ~/.bash_profile

nano  ~/.bash_login

nano  ~/.profile

Just look for the errant cd /workspace/test/app/helpers command in any/all of them and delete the command.

Also, if you are nervous about deleting anything in those files, just comment out the lines with a # and see what happens. As long as the command is commented out, it won’t run. And if it won’t run, no more error.

  • There is no mention of the cd command in any of those files. – Logan Serman Mar 26 '15 at 15:23
0

I just closed Terminal completely and started with a new window and it's fixed. Only new tabs in that old window were broken. Not sure what it was but... it's gone now.

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.