【问题标题】:git command not found in bash script on windows machine在 Windows 机器上的 bash 脚本中找不到 git 命令
【发布时间】:2020-03-12 15:43:25
【问题描述】:

我正在尝试为一些基本的 git 操作编写脚本,因为遇到问题git status: command not found

我正在试穿:
- Windows 机器
- bash 脚本
- 从git bash运行脚本
- git 安装在C:\Program Files\Git\mingw64\bin

下面是我正在尝试的示例脚本:

path_to_git='/c/Program Files/Git/mingw64/bin/'
PATH=$PATH:$path_to_git
echo $PATH
export PATH

res=$("git status")
echo $res

请指导我,谢谢

【问题讨论】:

  • 这里为什么要用双引号:res=$("git status")?
  • 你拯救了我的一天,感谢您的指导。

标签: bash git git-bash


【解决方案1】:

像您一样引用会使 shell 查找名为 git status 的命令,而不是带有参数 git 的命令 status – 去掉双引号:

res=$(git status)

然后不要echo那个没有引号,否则它会删除所有换行符:

echo "$res"

对于脚本,考虑使用

git status --porcelain

取而代之(请参阅documentation),使用更易于解析的版本化输出格式。

【讨论】:

  • 感谢您的回答。我不知道这个echo "$res" 关于换行符。
猜你喜欢
  • 2016-08-16
  • 2018-08-06
  • 2017-11-19
  • 2019-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-01
  • 2016-02-19
相关资源
最近更新 更多