[英]git script works when shell = /bin/sh but not when shell = /bin/bash. How to fix
I am using this script (filename git-proj-setup): 我正在使用此脚本(文件名git-proj-setup):
#!/bin/sh
if [ ! -d "project1" ]; then
echo Creating project1 folder
mkdir "project1"
fi
git clone git@gitserver:CDE/project1
cd ./project1
git checkout master
I run the script like this: 我这样运行脚本:
git proj-setup
When I run this script from my shell the program runs as expected: 当我从外壳运行此脚本时,程序将按预期运行:
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
But when I run from another machine, the script fails: 但是,当我从另一台计算机上运行时,脚本将失败:
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
But if I run the commands in the script from this second computer it DOES work as expected. 但是,如果我从第二台计算机上运行脚本中的命令,则它可以按预期运行。
This is running git for Windows on Windows 7. 这在Windows 7上为Windows运行git。
There is a slight difference in that it works on the PC where the latest Git for windows is installed: https://git-scm.com/download/win version 2.7.0 64 bit version. 有一点不同,它可以在安装了最新的Windows Git的PC上运行: https : //git-scm.com/download/win版本2.7.0 64位版本。 On the PC where it doesn't work it is running an earlier version of git. 在无法运行的PC上,它正在运行git的早期版本。 Not sure if that is relevant. 不确定是否相关。
Is the problem due to the different shell? 问题是由于外壳不同吗? How can I get one script to run on both the /bin/sh and also the /bin/bash shell? 如何在/ bin / sh和/ bin / bash shell上运行一个脚本?
The only condition to run a command git xxx
is that: 运行命令git xxx
的唯一条件是:
git-xxx
(no extension) 该脚本名为git-xxx
(无扩展名) PATH
所述脚本在PATH
That is working with an old git 1.9.5 msysgit-based or the more recent git for windows . 这可以在基于1.9.5 msysgit的旧git或针对Windows的较新git上使用 。
In both instance, you do not have to be in a git bash: you can run it directly from a regular CMD session. 在这两种情况下,您都不必使用git bash:您可以直接从常规CMD会话中运行它。
Double-check if git-proj-setup
is in one of the folders referenced by the PATH of the other machine. 仔细检查git-proj-setup
是否在另一台机器的PATH引用的文件夹之一中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.