【发布时间】:2016-01-18 10:59:09
【问题描述】:
我正在使用这个脚本(文件名 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
我这样运行脚本:
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。
在安装了最新的 Windows 版 Git 的 PC 上运行略有不同:https://git-scm.com/download/win 版本 2.7.0 64 位版本。在它不起作用的 PC 上,它运行的是早期版本的 git。不确定这是否相关。
问题是由于不同的外壳造成的吗?如何让一个脚本同时在 /bin/sh 和 /bin/bash shell 上运行?
【问题讨论】:
-
@AngusComber 是你的 $PATH 中的 git-proj-setup 吗?
-
您可能对 git 别名有不同的定义,具体取决于计算机($HOME/.gitconfig 或 .git/config)。
-
那显然和shell无关!
-
@TNW 这个问题很关键。为 PC2 添加固定的 PC2。但该文件夹不在 PC1 的路径中。奇怪。
-
请注意,
$SHELL是登录 shell,不一定是您当前正在运行的那个。