将git输出保存到变量

时间:2017-10-07 01:59:01

标签: git bash

我的bash脚本中有content= $(git diff --cached $line)

enter image description here

但是当我执行它时,bash抛出错误

gqqnbig MINGW64 /c/Website/Lender (master)
$ ./hook.sh
Admin/Xpress/BusinessAccountTypeRole_Edit.aspx
diff: unknown option -- git
diff: Try 'diff --help' for more information.

为什么$(git diff --cached $line)无法工作,以及如何修复它?

1 个答案:

答案 0 :(得分:4)

你在等号后加上一个空格。

content= $(git diff --cached $line)
        ^
      there

该空间表示Bash将环境变量content设置为该行的其余部分指定的命令的空字符串,而不是将shell变量content设置为运行该命令的结果。

相关问题