Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

shell - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

C:WINNTsystem32cmd.exe /c ""C:Gitinsh.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:empest.sh in the Git shell and leave it running, create this batch file :

C:WINNTsystem32cmd.exe /c ""C:Gitinsh.exe" --login -i -- D:empest.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 ~
$

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...