saves PWD to disk and sets previous PWD when starting a new BASH shell
The intended use is for systems that have users su - / sudo su - to use the root account (mainly Debian distros).
This script will cd the root/other user into their previous PWD. For example,
Terminal 1
- user1@Linux:~$
- user1@Linux:~$ sudo su - otherUser2
- otherUser2@Linux:~$
- otherUser2@Linux:~$ cd /var/log/
- otherUser2@Linux:/var/log$
Terminal 2 (or TAB)
- user1@Linux:~$
- user1@Linux:~$ sudo su - otherUser2
- otherUser2@Linux:/var/log$ <--- user is in same directory as before
My script adds this to the end of your .bashrc:
# save PWD to disk
function cd {
builtin cd "$@"
echo $PWD > ~/.previousPWD
}
cd "`cat ~/.previousPWD`"