using aliases in .bashrc 

*Tags*: :bash, :alias

> > It seems I can't use alias in .bashrc. To illustrate it, I put the
> > following 2 lines at the bottom of my .bashrc file:
> [...]
> Works fine on linux/hpux for both bash and bash2.
> [...]

Thanks Dan, which bash version are you using? I found that it might related with the bash version.

I put the following line to the top of my .bashrc file (which is going to be process before any other init scripts, right?)

alias bash_alias_test='echo just testing'; set -x; alias bash_alias_test
bash_alias_test; set +x; unalias bash_alias_test
if [ ${PS1:+T} ]; then
alias bash_alias_test='echo just testing'; set -x; alias bash_alias_test
bash_alias_test; set +x; unalias bash_alias_test
fi
alias bash_alias_test='echo just testing'; set -x; alias bash_alias_test
bash_alias_test; set +x; unalias bash_alias_test

and it works for one of my account that use bash 1.14.7. but for another account on the same machine which is using bash 2.04, I got:

+ alias bash_alias_test
alias bash_alias_test='echo just testing'
+ echo just testing
just testing
+ set +x
+ alias bash_alias_test
alias bash_alias_test='echo just testing'
+ bash_alias_test
bash: bash_alias_test: command not found
+ set +x
+ alias bash_alias_test
alias bash_alias_test='echo just testing'
+ echo just testing
just testing
+ set +x

So, can we conclude that bash 2.04 can no longer process alias defines in if clause now? Oh, I think now bash thinks if we define alias in if clause, it can only be used after the if statement.