我在 ~/.bash_profile 中设置了一个别名,如下所示:
alias lcmt="git show $(git log --oneline | awk '{print $1;}' | head -n 1)"
但是,每当我打开终端窗口时,我都会看到:
致命:不是 git 存储库(或任何父目录):.git
我已经能够将它缩小到那个特定的别名,因为当我注释掉它时,没有错误消息。为什么它在 OS X 上自行评估?我可以阻止它这样做吗?
最佳答案
双引号表达式中的 $(...)
在赋值时执行,即创建别名。您可以通过转义 $(...)
的 $
来避免这种情况。你想对 awk
命令中的 $1
做同样的事情:
alias lcmt="git show \$(git log --oneline | awk '{print \$1}' | head -n 1)"
关于bash - bash_profile 中的别名自行执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47501141/