Say you have directory ~/mytool that softlinks to /usr/local/mytool. Then cd mytool
leaves your current directory as ~/mytool, which may cause scripts to behave incorrectly. Is there a way to avoid this behaviour?
With some googling, I see that you can achieve this as follows:
cd $1 ; cd `pwd -P`
Is there no switch to 'cd'? Environment variables?
If you type
set -P
in bash all commands such as cd, pwd will follow the physical path. Else you can usecd -P
andpwd -P
for temporary changes to the default behavior.From the manpage of bash:
To make this permanent, put it in your
~/.bashrc
file, for example."cd" is a built in in most shells. In bash, you can get the behavior you want by adding
in a startup script (.bashrc, say).
On Ubuntu/Debian (not sure about BSD),
cd -P symlink
puts me in the resolved symlink path. (Same behavior as pwd -P)Tested using: