Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows shortcut to run a Git Bash script

Assuming I have a test.sh script that runs a server and Git Bash installed, how do I create a Windows shortcut that I can double click to run tesh.sh in Git Bash in the foreground and allows me to see the output of the server?

like image 455
konyak Avatar asked Feb 04 '14 21:02

konyak


People also ask

How do I run a Git script in bash?

Step 1: Go to Github repository and in code section copy the URL. Step 2: In the Command prompt, add the URL for your repository where your local repository will be pushed. Step 3: Push the changes in your local repository to GitHub. Here the files have been pushed to the master branch of your repository.

How do I automatically run a bash script in Windows?

On Windows, the simplest way of running a program at startup is to place an executable file in the Startup folder. All the programs that are in this folder will be executed automatically when the computer opens. You can open this folder more easily by pressing WINDOWS KEY + R and then copying this text shell:startup .

Can you run bash in CMD?

To access the shell, simply type 'bash' in the Windows command prompt, and everything is good to go.


1 Answers

Git bash is already a batch file with content similar to this :

C:\WINNT\system32\cmd.exe /c ""C:\Git\bin\sh.exe" --login -i" 

If you want run (and leave running) a shell script in the context of the shell, specify it at the command line. The trick is that when the script file name is interpreted, it uses the Windows path, not the equivalent path in the sh/Git environment.

In other words, to run the file D:\temp\test.sh in the Git shell and leave it running, create this batch file :

C:\WINNT\system32\cmd.exe /c ""C:\Git\bin\sh.exe" --login -i -- D:\temp\test.sh" 

On the other hand, if you want to run a script and get your shell back, you should :

  1. Open the shell as is
  2. Edit or create ~/.profile (try vi ~/.profile)
  3. Add this line : ~/test.sh (ajdust the path if needed)

So with a .profile that looks like this :

echo Executing .profile /bin/sh ~/test.sh 

And test.sh that looks like this :

echo Hello, World! 

You will get this prompt :

Welcome to Git (version 1.7.11-preview20120710)   Run 'git help git' to display the help index. Run 'git help <command>' to display help for specific commands. Executing .profile Hello, World!  ixe013@PARALINT01 ~ $ 
like image 87
ixe013 Avatar answered Sep 22 '22 03:09

ixe013