首页 > 解决方案 > 使用 shell 脚本克隆 git repo - Shell 在“.git”之后添加一个空格?

问题描述

我正在尝试做一个非常简单的任务,即将一个 git repo 和 cd 克隆到其中。

我有这个 shell 脚本:

#!/bin/bash
# Clone a git repository, and go into it
git clone git@someNumbers:myGitRepo.git
cd myGitRepo

当我运行它时,shell 认为 git repo 是“克隆 git@someNumbers:myGitRepo.git ”(有空格,我的代码中没有空格,我敢肯定)!

和输出:

Cloning into 'myGitRepo.git '...

当它应该说:

Cloning into 'myGitRepo'...

我还尝试将两个命令(一次)复制粘贴到命令提示符下,但同样会失败。只有单独运行它,或者在最后不使用 linebrake 的情况下复制粘贴它,才能成功克隆 git repo。

这里发生了什么?如何编写一个可以克隆 git 存储库的简单 shell 脚本?

标签: gitshell

解决方案


在您写的评论中od -tx1c myscript.sh显示. g i t 342 200 213 \n c d。那是U+200B ZERO WIDTH SPACE的 UTF-8 编码,显然它不被 shell 识别为空格。

如果您在编辑器中看不到它,只需删除整行,包括末尾的换行符,然后从头开始输入。


推荐阅读