bash - bash_profile 中的别名自行执行

标签 bash macos git-bash

我在 ~/.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/

相关文章:

arrays - Bash:从另一个数组中删除一个数组中存在的项目

python - 安装 opencv python mac osx 10.11?

node.js - 如何将文件夹添加到 .gitignore

linux - 检测MTD分区是否为UBI格式

bash - 在 Firefox 的 newtabs 中打开文件中的 url

linux - 有没有办法在 posix shell 或 bash 中扇出流?

cocoa - 密码管理器类型的应用程序,这很难吗?

macos - Mac 上的 Spark Shell "Failed to Initialize Compiler"错误

windows - 如何缩短 Git Bash 提示 (Windows)

java - BuildTools.jar Minecraft 服务器安装无法正常工作