Linux bash:git pull只有在它是最后一个命令时才起作用

Linux bash:git pull只有在它是最后一个命令时才起作用,linux,bash,git,sh,Linux,Bash,Git,Sh,平台:树莓皮3 B 请帮我解决这个问题,git pull只有在它是最后一个命令时才起作用,但我需要它更早。这对我来说很奇怪,我没有找到任何解决办法 工作 script.sh #!/bin/bash echo Hello World git pull #!/bin/bash echo Hello World git pull echo Hello World sh script.sh提供: Hello World Already up-to-date. Hello World ' is n

平台:树莓皮3 B

请帮我解决这个问题,git pull只有在它是最后一个命令时才起作用,但我需要它更早。这对我来说很奇怪,我没有找到任何解决办法


工作 script.sh

#!/bin/bash
echo Hello World
git pull
#!/bin/bash
echo Hello World
git pull
echo Hello World
sh script.sh提供:

Hello World
Already up-to-date.
Hello World
' is not a git command. See 'git --help'.


Did you mean this?
    pull
Hello World

不起作用 script.sh

#!/bin/bash
echo Hello World
git pull
#!/bin/bash
echo Hello World
git pull
echo Hello World
sh script.sh提供:

Hello World
Already up-to-date.
Hello World
' is not a git command. See 'git --help'.


Did you mean this?
    pull
Hello World

该文件具有错误的EOL格式(CRLF)。CRLF是来自windows应用程序上编写的文本文件的格式*NIX使用LF作为下线分隔符,因此解释器在每一行的内容中都会得到一个奇怪的字符(CR),它会作为您调用的命令的一部分传递到git上。。。这就是为什么它会断裂。运行
dos2unix script.sh
对其进行转换,以便正确读取。

该文件的EOL格式(CRLF)错误。CRLF是来自windows应用程序上编写的文本文件的格式*NIX使用LF作为下线分隔符,因此解释器在每一行的内容中都会得到一个奇怪的字符(CR),它会作为您调用的命令的一部分传递到git上。。。这就是为什么它会断裂。运行
dos2unix script.sh
对其进行转换,以便正确读取。

除了您的脚本可能有未关闭的引号或特殊字符外,没有其他原因。事实上,根据错误消息,它将
helloworld
视为git命令

就像你说的:

[vturlapati:~] $ git Hello World
git: 'Hello' is not a git command. See 'git --help'.

The most similar command is
    reflog
[vturlapati:~] $ git 'Hello World'
git: 'Hello World' is not a git command. See 'git --help'.

你能仔细检查特殊字符吗?如果您使用的是vim,那么可以通过执行
:set list

来实现这一点。除了您的脚本可能有未关闭的引号或特殊字符外,没有其他原因。事实上,根据错误消息,它将
helloworld
视为git命令

就像你说的:

[vturlapati:~] $ git Hello World
git: 'Hello' is not a git command. See 'git --help'.

The most similar command is
    reflog
[vturlapati:~] $ git 'Hello World'
git: 'Hello World' is not a git command. See 'git --help'.

你能仔细检查特殊字符吗?如果您使用的是vim,那么可以通过执行
:set list

#来实现这一点/usr/bin/env
?不响任何铃声。也许是
#/bin/bash
?@eftshift0与
#/bin/bash
行为是相同的
file script.sh
说什么?@eftshift0
$file script.sh script.sh:Bourne脚本,ASCII文本可执行,带有CRLF行终止符
#/usr/bin/env
?不响任何铃声。也许是
#/bin/bash
?@eftshift0与
#/bin/bash
行为是相同的
file script.sh
说什么?@eftshift0
$file script.sh script.sh:Bourne脚本,ASCII文本可执行文件,带有CRLF行终止符
现在工作正常,谢谢:-)文件是在Windows中编写的,我知道他们有不同的
\n
,但我今天没有怀疑这似乎是关于我打字时的回答。我会选择这个,因为它还有一个解决方案/修复程序。现在可以了,谢谢:-)该文件是在Windows中编写的,我知道它们有不同的
\n
,但我今天没有怀疑这一点。看起来这是关于我键入我的时的回答。我会选择这个,因为它还有一个解决方案/修复方案。