bash别名扩展

时间:2012-02-01 07:33:58

标签: bash shell command-line

有没有办法在命令行上“扩展”bash别名并获取其背后的命令? 所以它例如将ls变为;

ls --color=auto

当我的别名几乎完成我想做的事情时,我会不断陷入困境......但不完全......

这是否可能是所有建议或答案都赞赏

2 个答案:

答案 0 :(得分:1)

尝试

$ alias alias_name 

它将显示给定别名的扩展

答案 1 :(得分:1)

一种更复杂的方式,适合回声:

$ cut -d = -f1 --complement< <(alias alias_name) | tr '"'"'" ' '

所以,在像

这样的函数中
exp() { 
  cmd=$1 
  shift 
  echo $(cut -d = -f1 --complement< <(alias $cmd) | tr '"'"'" ' ') $@
}
在所有扩展到位后,

将导致回显命令,因为它将发布到shell。

这可能对调试很有用。

$ exp ll .*
ls -l --color=tty . .. .bash_history .bash_logout .bash_profile .bashrc .lesshst