I'm using ConEmu on Windows with Git for Windows installed. When I try to execute an .sh script, the software starts an instance of Windows' default console and executes the script there. How can I make ConEmu / Git for Windows execute the .sh script in the same window the command is initialized from?
-
You have not described how exactly you are trying to run the script! – Maximus Mar 25 '16 at 08:06
-
You also posted this on [su]. Please do **not** crosspost. See [Is cross-posting a question on multiple Stack Exchange sites permitted if the question is on-topic for each site?](http://meta.stackexchange.com/q/64068) – DavidPostill Mar 25 '16 at 08:45
-
@Maximus I just type the script's filename into ConEmu and it runs when I press enter. I'm assuming it's handled automatically by Git for Windows. – ThePiachu Mar 25 '16 at 10:11
-
We still do not know what shell do you use and hire do you start it in ConEmu. – Maximus Mar 25 '16 at 13:37
-
@Maximus How would I figure out which shell I use? – ThePiachu Mar 26 '16 at 00:46
-
Don't you know what you are working with? Look at ConEmu settings: Startup. Look at ConEmu status bar at last. – Maximus Mar 26 '16 at 03:33
-
@Maximus Here are my ConEmu startup settings - https://imgur.com/bdtgaRn . CMD shell? – ThePiachu Mar 26 '16 at 06:06
-
run `bash yourscript.sh` to reuse console – Maximus Mar 26 '16 at 10:16
-
@Maximus > bash all.sh 'bash' is not recognized as an internal or external command, operable program or batch file. – ThePiachu Mar 26 '16 at 19:21
-
@Maximus Okay, it looks like my Git/bin wasn't included in PATH. I'll have to try doing that and see if it fixes my issue. – ThePiachu Mar 26 '16 at 19:42
-
Also see https://superuser.com/a/454381/78786 – marcovtwout Dec 11 '17 at 12:32
1 Answers
So there are a few things one needs to do after a clean install of ConEmu and Git for Windows to make everything run seamlessly.
1) C:\Program Files\Git\bin
needs to be added to PATH. Git for Windows only appears to add C:\Program Files\Git\cmd
to PATH. This should allow you to run commands like sh test.sh ABC
and they should work
2) To make things even easier and not have to type sh
all the time, we need to tell Windows to associate .sh with sh, as well as pass parameters properly. We do this by typing:
assoc .sh=sh
ftype sh="C:\Program Files\Git\bin\sh.exe" "%1" %*
3) If parameters are still not passed, it might be a registry issue. To fix it, we press Win+r, type in regedit
and run the Registry Editor. There might be a few places where the edit needs to be made, but one of them should be HKEY_CLASSES_ROOT\Applications\sh.exe\shell\open\command
. We edit the entry to say
"C:\Program Files\Git\bin\sh.exe" "%1" %*
4) Bonus: To make .sh files execute without having to write ".sh" at the end, add .SH to PATHEXT
in environmental variables.
That should allow us to run .sh files from ConEmu using Git for Windows without it opening in a separate window.

- 8,695
- 17
- 65
- 94
-
One note. Adding `git/bin` or `git/usr/bin` may break .cmd scripts, if the directory contains such files as `find.exe`. So, it's preferable to modify `PATH` in the ConEmu task command. – Maximus Mar 27 '16 at 09:51