symlinkbash

Does `source` automatically follow symbolic links? - Bash


I was wondering if source ~/.bashrc will work even when ~/.bashrc is a symbolic link to a file located somewhere else?


Solution

  • Of course. Bash tries to open the designated object, the filesystem follows the symbolic link on the fopen call.

    But the current directory remains ~, which means that other profile files in the directory you're linking to are not visible by the rc file pointed by the link.

    So the interest is limited.

    Also note that you should not test existence with if [ -f ~/.bashrc ]; then source ~/.bashrc fi because -f tests for regular file. You want -e flag (means: name points to something valid)