简体   繁体   English

git脚本在shell = / bin / sh时起作用,而在shell = / bin / bash时不起作用。 怎么修

[英]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的唯一条件是:

  • the script is named git-xxx (no extension) 该脚本名为git-xxx (无扩展名)
  • said script is in the 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.

相关问题 如何在windows Git shell中运行./script.sh? - How to run ./script.sh in windows Git shell? bash shell脚本错误sh:[:缺少`]' - Bash shell script error sh: [: missing `]' 将Git添加到/ bin / bash - Adding Git to /bin/bash 恢复 git 中的 shell 脚本文件 (.sh) - Restore a shell script file (.sh) in git 在 Git for Windows 的安装路径中,./git-bash.exe 与 bin/bash.exe 和 bin/sh.exe 有什么区别? - In the install path of Git for Windows, what's the difference between ./git-bash.exe and bin/bash.exe and bin/sh.exe? What does shell: /bin/bash -e {0} mean in bash shell output from a github action worker? - What does shell: /bin/bash -e {0} mean in bash shell output from a github action worker? 使用python脚本打开Git Bash shell,然后在git bash shell中运行shell脚本 - Open Git Bash shell using a python script and then run a shell script in git bash shell 在 Git bash 在 ZAEA23489CE3AA9B6406EBB28E0CDA4 中全局运行 shell 脚本 - Run shell script globally in Git bash in Windows 在窗口git bash中运行shell时找不到sed命令 - sed command not found when run shell in window git bash 当使用php exec()运行shell脚本时,一个脚本工作(它只是git状态)而一个脚本没有(它执行git checkout)。 怎么会? - When using php exec() to run shell scripts, one script works (which simply does git status) and one doesn't (which does git checkout). How come?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM