On my system I have zsh and tcsh installed. I usually use zsh but some scripts use tcsh. Normally, in a terminal window, if I type
tcsh
mec-0569x:~>
I get the prompt up as expected. If the terminal window has been open for a while, however, and I type tcsh, I get
tcsh
tcsh: No such file or directory
tcsh: Trying to start from "/home/james"
mec-0569x:~>
I'm not sure if it's related to the time the window has been open, or a particular script I'm running in the window, but if I close the terminal window and open a new one, change directory to the folder I was in, it works perfectly fine. What should I be looking for to solve this?
The problem is probably that the directory you were in was removed, and that a new directory with the same pathname was created after that.
This is not the same directory;
getcwd()
uses inodes to get the pathname of a directory, this new directory has a different inode, and the inodegetcwd()
want to use doesn't exist anymore.When you type
tcsh
, it inherits the (nonexistent) working directory from the parent process; on startup,tcsh
wants tochdir()
to the current working directory, but this doesn't exist anymore, so you get an error (and itchdir()
s to the home directory).You can solve this by
cd
-ing to the full pathname withcd "$PWD"
before startingtcsh
, this sets the correct working directory for the parent process.