在Git Bash中运行.sh脚本

在Git Bash中运行.sh脚本

问题描述:

我在使用Git 2.7.2.windows.1和MinGW 64的Windows计算机上.

I'm on a Windows machine using Git 2.7.2.windows.1 with MinGW 64.

我在C:/path/to/scripts/myScript.sh中有一个脚本.

如何从Git Bash实例执行此脚本?

How do I execute this script from my Git Bash instance?

可以将其添加到.bashrc文件中,然后仅执行整个bashrc文件.

It was possible to add it to the .bashrc file and then just execute the entire bashrc file.

但是我想将脚本添加到一个单独的文件中,然后从那里执行.

But I want to add the script to a separate file and execute it from there.

假设您有一个脚本script.sh.要运行它(使用Git Bash ),请执行以下操作: [a] 在第一行(例如#!/bin/bash)上添加"sh-bang"行,然后然后 [b] :

Let's say you have a script script.sh. To run it (using Git Bash), you do the following: [a] Add a "sh-bang" line on the first line (e.g. #!/bin/bash) and then [b]:

# Use ./ (or any valid dir spec):
./script.sh

注意:chmod +x对脚本在Git Bash上的可执行性没有任何作用.运行它不会有什么坏处,但是它也不会完成任何事情.

Note: chmod +x does nothing to a script's executability on Git Bash. It won't hurt to run it, but it won't accomplish anything either.