在别名使用上打印bash命令

时间:2016-09-14 22:41:41

标签: macos shell terminal .bash-profile

我最近设置了很多别名,它为我节省了一些打字但是我担心这可能会让我忘记原来的命令。 有没有办法使用别名,同时打印原始命令。 例如,在这个别名上,它会是什么样的?

alias showhidden='defaults write com.apple.finder AppleShowAllFiles YES'
  • JOR

1 个答案:

答案 0 :(得分:1)

呃,这看起来过于简单了,但是怎么样:

$alias showhidden='echo defaults write com.apple.finder AppleShowAllFiles YES;defaults write com.apple.finder AppleShowAllFiles YES'

或者我刚试过的一个更简单的例子:

$alias lsl='echo ls -l;ls -l'
$lsl
ls -l
total 120
-rw-r--r--  1 ian  staff     20 Sep 14 21:29 iplist.txt
-rw-r--r--  1 ian  staff  55856 Sep 14 21:42 t.out

如果您要将这些命令用作管道的一部分,那么这可能是一个坏主意,因此可能会发送"提醒" stderr会努力让他们分开吗?

$alias lsl='echo ls -l >&2 ; ls -l'