gpt4 book ai didi

bash - bash_profile 中的别名自行执行

转载 作者:行者123 更新时间:2023-11-29 09:36:14 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com