Reputation: 13468
If I add the alias alias .="cd .."
to my .bash_aliases file (sourced from .bashrc) it causes every new shell I make to start at /
. I am guessing this is just a fundamental thing I don't understand.
Any ideas?
Upvotes: 1
Views: 1522
Reputation: 125708
.
is a builtin shell command, equivalent to "source" -- it executes a shell script in the current shell, thus allowing it to define variables, functions, etc.
This .
command is used fairly often in scripts to bring in definitions from other scripts. When you alias .
to something else, you override the standard definition and break every script that uses it.
Please do not redefine standard commands.
(P.S. it's actually more complicated than that, because aliases are only active in interactive shells, so .
would do completely different things in interactive vs. non-interactive shells. This doesn't really help the situation.)
Upvotes: 2
Reputation: 289505
.
refers to the current directory, while ..
refers to the one upper in the dirs hierarchy.
What must be happening is that in your bashrc
you have some .
after this alias definition, so it gets called and hence you are moved to the parent directory.
So:
/home/your_home
alias .="cd .."
..
is found while reading .bashrc
.cd ..
, which moves you to /home
..
and it must get executed again, moving you from /home
to /
.Solution:
Upvotes: 1