Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git脚本在shell=/bin/sh时工作,但在shell=/bin/bash时不工作。如何修复_Git_Bash_Shell - Fatal编程技术网

git脚本在shell=/bin/sh时工作,但在shell=/bin/bash时不工作。如何修复

git脚本在shell=/bin/sh时工作,但在shell=/bin/bash时不工作。如何修复,git,bash,shell,Git,Bash,Shell,我正在使用此脚本(文件名git proj setup): 我按如下方式运行脚本: git proj-setup 当我从shell运行此脚本时,程序按预期运行: person1@comp1 /c/dev $ git proj-setup Creating project1 folder Cloning into 'project1'... remote: Counting objects: 3, done. Receiving objects: 100 remote: Total 3 (delt

我正在使用此脚本(文件名git proj setup):

我按如下方式运行脚本:

git proj-setup
当我从shell运行此脚本时,程序按预期运行:

person1@comp1 /c/dev
$ git proj-setup
Creating project1 folder
Cloning into 'project1'...
remote: Counting objects: 3, done.
Receiving objects: 100
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), 275 bytes | 0 bytes/s, done.
Checking connectivity... done.
Already on 'master'
Your branch is up-to-date with 'origin/master'.

person1@comp1 /c/dev
$ echo $SHELL
/bin/sh
但当我从另一台机器运行时,脚本失败:

person2@comp2 MINGW64 /c/dev
$ git proj-setup
git: 'proj-setup' is not a git command. See 'git --help'.

person2@comp2 MINGW64 /c/dev
$ echo $SHELL
/usr/bin/bash
但是,如果我在第二台计算机上运行脚本中的命令,它确实会按预期工作

这是在Windows 7上运行git for Windows

有一点不同,它在安装了最新Git for windows的PC上工作:版本2.7.0 64位版本。在无法工作的PC上,它运行的是早期版本的git。不确定这是否相关


问题是由不同的外壳引起的吗?如何让一个脚本同时在/bin/sh和/bin/bash shell上运行?

运行命令的唯一条件是:

  • 脚本名为
    git xxx
    (无扩展名)
  • 所述脚本位于路径
与旧的或旧的设备一起工作。
在这两种情况下,您不必使用GitBash:您可以直接从常规CMD会话运行它


仔细检查另一台计算机的路径所引用的文件夹中是否有
git proj设置。

@anguscommber是您的git proj设置在$PATH中吗?根据计算机($HOME/.gitconfig或.git/config),您可能对git别名有不同的定义。这显然与shell无关@这个问题是关键。在PC2上添加已修复的PC2。但文件夹不在PC1上的路径中。奇怪。请注意,
$SHELL
是登录SHELL,不一定是您当前正在运行的SHELL。您的答案是正确的,因为当我在PC2上添加path时,它工作了。但奇怪的是,在我的PC上,我运行脚本的路径,当前目录(.)不在我的路径中,但它工作了。无论如何,添加到路径修复。@AngusComber从不将
添加到您的路径!否则,获得用户权限的黑客可以“覆盖”系统命令。
person2@comp2 MINGW64 /c/dev
$ git proj-setup
git: 'proj-setup' is not a git command. See 'git --help'.

person2@comp2 MINGW64 /c/dev
$ echo $SHELL
/usr/bin/bash