I am trying to make an alias that overrides the cd
command. This is going to execute a script before and after the "real" cd
.
Here is what I have so far:
alias cd="echo before; cd $1; echo after"
This executes the echo before
and echo after command
however it always changes directory ~
How would I fix this?
I also tried cd(){ echo before; cd $1; echo after; }
however it repetedly echos "before".
set /bin
and then your alias definition:alias cd="echo before; cd $1; echo after"
and thencd
. You'll see that you're not in your home but in/bin
. Now, exercise for you: why? hint: what is$1
? check your answer withalias cd
: this will print whatcd
is aliased to.