Confirming The current working directory IS based on the inode number, not what you looked up to get there. Since you are using bash, you can use $PWD as follows to cd to the new directory of the same name:
cd $PWD
To illustrate, I made a dummy deploy command:
set -x
cd ~/tmp
rm -rf code
mkdir code
echo echo hello from $* > code/run
chmod +x code/run
Created the first deployment, cd'd to code and then checked contents with ls -lai
so you can see the inodes:
ianh@abe:~/tmp$ ./,deploy first
++ cd /home/ianh/tmp
++ rm -rf code
++ mkdir code
++ echo echo hello from first
++ chmod +x code/run
ianh@abe:~/tmp$ cd code
ianh@abe:~/tmp/code$ ls -lai
total 12
22945913 drwxr-xr-x 2 ianh ianh 4096 Apr 9 23:12 .
22937618 drwxrwxr-x 14 ianh ianh 4096 Apr 9 23:12 ..
22939455 -rwxr-xr-x 1 ianh ianh 22 Apr 9 23:12 run
Now run the 2nd deploy
ianh@abe:~/tmp/code$ ../,deploy 2nd
++ cd /home/ianh/tmp
++ rm -rf code
++ mkdir code
++ echo echo hello from 2nd
++ chmod +x code/run
And check the directory contents ... now there isn't anything in the directory! not even '.' and '..'! From this you can see that bash is not using the '..' directory entry when you run cd ..
since '..' no longer exists - I presume its part of its $PWD handling. Some other/older shell's don't handle cd ..
in this situation, you have to cd to an absolute path first.
ianh@abe:~/tmp/code$ ls -lai
total 0
Cd to $PWD
and try again:
ianh@abe:~/tmp/code$ cd $PWD
ianh@abe:~/tmp/code$ ls -lai
total 12
22945914 drwxr-xr-x 2 ianh ianh 4096 Apr 9 23:12 .
22937618 drwxrwxr-x 14 ianh ianh 4096 Apr 9 23:12 ..
22939455 -rwxr-xr-x 1 ianh ianh 20 Apr 9 23:12 run
ianh@abe:~/tmp/code$ ./run
hello from 2nd
Note how the inode for the current directory (.) changed?
If your deploy script moved the old directory to some other name, eg mv code code.$$
in the ,deploy script above, then ./run
would work, but until you use cd $PWD
you would be running the old code, not the new.
ianh@abe:~/tmp/code$ ./run
hello from 2nd
ianh@abe:~/tmp/code$ ../,deploy 3rd
++ cd /home/ianh/tmp
++ '[' -d code ']'
++ mv code code.9629
++ mkdir code
++ echo echo hello from 3rd
++ chmod +x code/run
ianh@abe:~/tmp/code$ ./run
hello from 2nd
ianh@abe:~/tmp/code$ cd $PWD
ianh@abe:~/tmp/code$ ./run
hello from 3rd
Deploying using capistrano has the same issue (They have a symlink from the name current to the current release), so I use aliases to cd to the production/staging areas as well as set RAIL_ENV appropriately:
alias cdp='export RAILS_ENV=production; echo RAILS_ENV=$RAILS_ENV ; cd /var/www/www.example.com/current'
alias cds='export RAILS_ENV=staging; echo RAILS_ENV=$RAILS_ENV ; cd /var/www/staging.example.com/current'
run
is the same as the old directory. It only has the same name and parent directory. Compare this to you shredding your old car and buying a new car of the exact same color and model: You would not want to sit in the car being shredded and hope you end up on the new one unharmed, would you?cd ../code
is not a noop...
is a shortcut for the parent of the path that you have, or used to have. If your current directory is deleted the parent path might still exist, and in this case be reachable by evaluating..
. In that directory a search is done for a directory with name 'code'.