Bash路径名扩展和使用git?

时间:2017-03-20 18:38:20

标签: git bash

我现在一直在我的键盘上抨击这个问题太久了,如果没有得到很多相似但最终无益的问题,很难找到。

我在共享驱动器上有一组git存储库,我使用一些bash脚本进行管理。现在,我被迫使用双启动设置来处理一些我无法在wine下工作的软件,所以我的问题是在windows 7中专门用git bash。

我有一些像这样的代码:

win_shared="//path/to/shared/drive/RepoParentDir/"
nix_shared="/mnt/shared/RepoParentDir/"

// ... other stuff ...

# $dir is the current repo working directory (in a loop),
# and $working is the local path above RepoParentDir (fixed for lifetime of the script)
repo_dir=${dir#$working/}

nix=$(printf '%q' "$nix_shared$repo_dir.git")
echo "\$nix = $nix"
git remote add nix_origin "$nix"

win=$(printf '%q' "$win_shared$repo_dir.git")
echo "\$win = $win"
git remote add win_origin "$win"

git remote -v

// ...

但是,这是我得到的输出(省略了冗余git pull路径):

$nix = /mnt/shared/RepoParentDir/clients/Client\ Repo\ Name.git
$win = //path/to/shared/drive/clients/Client\ Repo\ Name.git

nix_origin  C:/Program Files/Git/mnt/shared/RepoParentDir/clients/Client/ Repo/ Name.git (fetch)
win_origin  //path/to/shared/drive/RepoParentDir/clients/Client/ Repo/ Name.git (fetch)

注意回显时转义是如何正确的,但是一旦转到git add remote命令,转义就会用错误的斜杠完成,而git bash的路径会被添加到我的linux路径变量中。

我已经尝试过类似的关于bash路径名扩展的问题的各种事情,这就是我在printf解决方案中使用转义字符串的方法,但当我输出“$ nix”时我遇到了类似的问题直接“$ win”并且git会阻塞或以不正确的远程路径结束。

我不确定这里到底发生了什么,因为我仍然是bash和unix noob。

编辑:

我还注意到,在我的日志文件中,仅当路径名称只包含需要转义的空格而没有其他特殊字符时才会发生这种情况。但是,如果路径名中有任何其他特殊字符,比如撇号(我的一些存储库中有),那么所有的转义都是正确完成的,并且完全按照我期望的方式输出echo和git命令,在这种情况下,它也不会将C:/Program Files/Git/添加到路径中。无论同一路径名中是否还有空格,都是这种情况。所以,用:

/mnt/shared/RepoParent/Client's Repo Name.git
/mnt/shared/RepoParent/Client'sRepoName.git
/mnt/shared/RepoParent/[ClientRepoName].git
/mnt/shared/RepoParent/[Client Repo Name].git

我得到了

/mnt/shared/RepoParent/Client\'s\ Repo\ Name.git
/mnt/shared/RepoParent/Client\'sRepoName.git
/mnt/shared/RepoParent/\[ClientRepoName\].git
/mnt/shared/RepoParent/\[Client\ Repo\ Name\].git

正如我所料。

很抱歉,如果这很难理解。

0 个答案:

没有答案