I was just writing a C++ program on my Ubuntu 14.10 computer. As it is a client/server program, I has three terminal emulators open: one for writing code and compilation, one for client testing, and the last one for server testing. After a while, I thought I had a bug in my code. I lost over an hour tracking it down, and it turned out that getting out of directory and entering it again solved the whole problem. To be precise these were the commands I executed:
some_directory$ ./client
some_directory$ cd ..
$ cd some_directory
some_directory$ ./client
Without changing anything—and without recompilation—the two runs gave different results. The only thing I can think of is some kind of cache that would store old version of files, but I never heard about such a feature. Is there an explanation, and how to solve it (make it refresh automatically, without exitting directory)?
2 Answers
I don't think bash does anything that fancy (it does cache paths to executables specified without paths, but that doesn't apply here, since you are specifying the path)
Sounds like the directory you were in was moved or mounted over. In the case of building software, the directory move is more likely.
Directory move case
An example of recreating the behaviour of a directory move, in terminal 1
cd /tmp
mkdir dir1
cd dir1
touch exampleFile
Then in terminal 2:
cd /tmp
mv dir1 dir2
mkdir dir1
cd dir1
Both shells show as being in a directory named 'dir1', but a listing will show different contents. If terminal2 creates a file called 'exampleFile', both shells will show 'exampleFile' in 'dir1' but they are different files. This is because the shell in terminal 1 is in fact in dir2 now, it just doesn't know it. The shell in terminal 1 can get to the real 'dir1' via cd:
cd .
This looks weird but re-resolves the path.