cmd:alias 

Use alias everywhere 

Symptom 

Can't use var-held alias as pipe command:

$ alias alias_tst
alias alias_tst=echo
ChkCmd=alias_tst
ls *.rpm | $ChkCmd
-bash: alias_tst: command not found

Solution 

Use eval.

ls *.rpm | eval $ChkCmd

alias expansion 

Situation 

when an alias will be expand and when not?

Conclusion 

  • Aliases would only be expand in function definition.

Analysis 

$ alias ls='ls --color=auto '
$ alias dir='ls -lF '
$ alias
alias dir='ls -lF '
alias ls='ls --color=auto '

— alias ls in alias dir is not expanded.

$ lf(){ dir "$@" | grep -v '^[dl]' ;}
$ type lf
lf is a function
lf ()
{
    ls --color=auto -lF "$@" | grep -v '^[dl]'
}

— alias dir in function lf is fully expanded.

documented on: 1999.12.03 Fri 14:12:03