Can bash aliases be paths?
Hi and sorry in advance for the noob question. I noticed a strange behavior when using bash aliases.
is to use short bash aliases for often used paths, to make navigation in the shell easier. As an esample, to quickly navigate to a university (
uni) folder on a data drive mounted at
/mnt/data I used the bash alias
alias uni='/mnt/data/uni'. Now, if I am in the parent directory
/mnt/data and run
cd uni, this works as I though it would and I move to
However if I am on another drive, say in my root directory and I run the same, I get the error
bash: cd: uni: No such file or directory. If I only execute
uni, the output is
bash: /mnt/data/uni: Is a directory indicating that bash "understands" that this is a directory. However, for some reason, when not in the parent directory, the alias can not be used with the cd function to move to the directory.
If I add the
cd command to my alias so that it reads
alias uni='cd /mnt/data/uni', the alias works from all directories. However I would like to have only the path in the alias to be able to use other functions with it. Now I could live with including the
cd into the alias because 99% of operations I do with these directories is just navigation but what bugs me most is that I obviously don't fully understand how aliases work in this situation.
Could somebody explain why my alias behaves this way and what I am missing here? A solution to only alias the path would also be handy.
Thanks a lot! Cheers