Git for windows bash 脚本的执行路径不正确

Git for windows bash execution path for a script not correct

当码

SRC=$(cd $(dirname "[=13=]"); pwd)

在 Bash 脚本中执行,该系统在 c:\program files\Git 中安装了 Git for Windows,SRC 将获得值 /c/program .

如何进行这项工作? 我需要获取脚本所在的路径,并使用它来包含具有相对路径的其他脚本。 在我的例子中,下一行是: 来源“${SRC}/common/common.sh

脚本在 c:\program files\Git\usr\bin 中,因此我可以使用 git <command-name> 并使用一些有用的手工命令扩展 Git,用于具有 rebase 和子模块的功能分支工作流。
如果有人想帮忙,源代码在 https://github.com/jlovs/git-scripts

您需要双引号 cd 命令的参数。

SRC=$(cd "$(dirname "[=10=]")"; pwd)

命令替换 $(dirname "[=12=]") 扩展为包含 space 的路径。下面的 cd 命令有两个参数,而你只想传递一个参数,里面有一个 space。

您无需担心另一对引号中 [=14=] 周围的引号,因为 $() 命令替换会启动一个新的 quoting context.

如您所述,您 运行 使用 MINGW64。您可以尝试使用cygpath -aw将路径转换为windows格式:

SRC=$(cygpath -aw $(cd "$(dirname "[=10=]")"; pwd))

更多信息here and here