I am writing a bash script that moves an existing directory to a new name, creates a new directory with the old name and then changes into that newly created directory. Strangely, the new directory is not empty but contains everything from the old, now renamed, directory. But the move was succesfull, the renamed directory exists and contains what it shall contain. And if I compare inodes, I'm still in the renamed directory, but the name indicated with 'pwd' shows that I should be in the new directory.
To make things more clear, I'm starting off in the directory I want to create a backup from. The script essentially does the following:
cd <away>
mv <olddir> <olddir>~
mkdir <olddir>
cd <olddir>
I am using full pathnames; using pushd/popd gives the same result. The result is very strange (test9 is an empty file I created to easily see if I'm in the expected directory):
/opt/camera_pkg_sdk$ ls -ia1
20578307 .
20447233 ..
20578305 test9
/opt/camera_pkg_sdk$ ls -ia1 ../camera_pkg_sdk
20578306 .
20447233 ..
/opt/camera_pkg_sdk$
Inode 20578307 is the renamed directory, 20578306 is the new one. I tried inserting 'sync' in various locations in my script, without any luck. If, on the command line after the script has run, I manually go up one level and then back, all is normal again, and I see the correct inode numbers.
Any idea what to try? How to work around? What is the reason? Or even have a true solution? I am as interested in the why it happens, as in a working way to achieve what I need.
<away>
located wrt<olddir>
?