调用后如何将OS X bash别名命令回显到终端(如!cmd)?

问题描述:

在〜/ .bash_profile中定义了别名,例如。 alias vaguppro ='vagrant up --provision

In ~/.bash_profile aliases are defined, eg. alias vaguppro='vagrant up --provision

我想要的是的回声在终端中键入 vaguppro 后,请vagrant up --provision

What I want is an echo of vagrant up --provision after typing vaguppro in the terminal.

类似于when一种是在终端中键入 ls -hal ,然后再次键入!ls 。在执行之前,终端中会出现 ls -hal 的回声。

Similar to when one types ls -hal in the terminal, then again type !ls. There's an echo of ls -hal in the terminal before execution.

某些解决方案

vaguppro='vagrant up --provision'
alias vaguppro='echo $vaguppro && $vaguppro'

或下面的andlrc函数解决方案。

or andlrc's function solution below.

您可能会发现此快捷方式很有用:

You may find this shortcut useful:

   shell-expand-line (M-C-e)
          Expand the line as the shell does.  This performs alias and his‐
          tory expansion as well as all of the shell word expansions.  See
          HISTORY EXPANSION below for a description of history expansion.

换句话说,如果您写 vaguppro 然后在bash的默认Emacs模式下按 Ctrl + Alt + E ,它将在当前行中扩展别名并将其转换为浪费--provision 。然后,您可以按Enter键照常运行。

In other words, if you write vaguppro and press Ctrl+Alt+E in bash' default Emacs mode, it will expand aliases in the current line and turn it into vagrant up --provision. You can then press enter to run as usual.