bash_profile 中的别名自行执行

pyd*_*oge 2 macos bash git-bash

我在 ~/.bash_profile 中设置了一个别名,如下所示:

alias lcmt="git show $(git log --oneline | awk '{print $1;}' | head -n 1)"

但是,每当我打开终端窗口时,我都会看到:

fatal: Not a git repository (or any of the parent directories): .git

我已经能够将其缩小到该特定别名,因为当我将其注释掉时,没有错误消息。为什么它在 OS X 上自行评估?我可以阻止它这样做吗?

Sto*_*ica 6

$(...)双引号内的表达得到的分配,创建别名时执行。您可以通过逃避避免$$(...)。并且您想对命令$1内部执行相同的操作awk

alias lcmt="git show \$(git log --oneline | awk '{print \$1}' | head -n 1)"
Run Code Online (Sandbox Code Playgroud)