Is git bash something that can be used as a windows alternative to terminal on ubuntu? Can we use cmd.exe for the same purpose?
Git bash exists as a minimal environment for running git on Windows. Git itself consists of a number of shell and Perl scripts as well as binaries. In order to run them you need an environment that can interpret shell scripts. A Windows command prompt can only interpret Batch files.
Note that git bash doesn't have much more than the shell, git, ls, and a few other utilities. If you need a more complete shell and tool suite then look at https://www.cygwin.com/ instead.
Git BASH provides a BASH emulation used to run Git from the command line. Unix users should feel right at home, as the BASH emulation behaves just like the "git" command in LINUX and UNIX environments.
Also it is used to run commands of Linux such as ls,cd etc. If you want to use commands in Windows go install GIT BASH.
You cannot use command prompt for same purpose.
Related
Problem
When I run a bash script on Windows:
bash my_script.sh
I get linux-gnu for $OSTYPE inside the script.
Why is this like this?
I assume that i have WSL installed is relevant here.
Tested in PowerShell and CMD.
Git bash is returning msys like expected! Thx #user1934428
Background
I want to start some python scripts from bash, but not inside WSL.
From my command line I reach different python versions on windows, but from inside the bash scripts it is using the one inside WSL (except for GitBash).
You're right, running the bash command in PowerShell or CMD will launch WSL to run your script. You confirm this (and see which version of WSL) by running cat /etc/issue in your bash script. Your WSL environment will have an independent set of environment variables (not just $OSTYPE). You can see this by comparing the output of Get-ChildItem -Path Env:\ in PowerShell to the output of env (after you launch bash from PowerShell).
I suspect that the python version discrepancy you're seeing is a result of the PATH variable in your WSL runtime not matching what you have set in your PowerShell environment. You can fix your version issue by setting an alias containing a path to the python executable you want to use by adding alias python=/c/path/to/python.exe to the start of your bash scripts.
Alternatively, you can use a tool like Cygwin or git-bash to run your scripts. I'm not sure if they will use the same path variables as Windows so you may need to set those manually too.
Clicking on a .sh script inside Eclipse (on Windows) executes it using Git Bash for Windows. However, I'd like to use Cygwin bash instead.
There is an option which looks like this:
I removed the shown entry for Git Bash and added an entry with a path to the Cygwin bash executable. However, this doesn't change anything - Git Bash for Windows is still used - and after closing and opening Eclipse the Git Bash entry is there again.
How can I configure Eclipse to use Cygwin bash?
You could also use https://marketplace.eclipse.org/content/bash-editor
Here you can customize the command
A description how to launch the scripts can be found at
https://github.com/de-jcup/eclipse-bash-editor/wiki/FAQ#how-can-i-execute-shell-scripts-with-bash-editor
The plugin contains also an integrated bash debugger which should work with cygwin bash as well. For the debugger in action on a Windows 10 machine you can look at YouTube Video - Bash editor debugging on Windows 10. Here you can see the default configuration done to execut git bash. Of course you have to customize start command a bit, but I think it's feasable.
PS: I am the maintaner of the mentioned plugin
I installed Git For Windows 2.7.2 a few days ago. Now I have some problems with using optional tools Git For Windows provides from cmd.exe. In the previous version of Git For Windows(or say msysgit), I could configure these tools by modifying Git/etc/git-completion.bash. For example:
alias ls='ls --show-control-chars --color=auto'
I used this way to make ls display file names that contained Chinese characters normally. Now it seems this way doesn't work. In fact there is no git-completion.bash under Git/etc/. There is a git-completion.bash under the folder Git/mingw64/share/git/completion. I tried to copy it to Git/etc and add the alias above, which didn't work either. These tools only works fine in Git Bash. So how should I configure these tools together with git to use them from cmd.exe?
This answer explains why you no longer have this functionality. In short, msysgit provided a unix shell emulator, mingw. Git for Windows is git compiled in a Windows environment.
Therefore, ls is simply an alias for dir in a Windows shell, not mingw's ls. If you want to create some Windows aliases, you can use doskey. Here's an answer for that.
Alternatively, I would suggest that you just start using PowerShell, where you'll be able to set up the $profile variable with some powerful commands like these.
I've just started with Git, and I can't figure out how to enable command line for Git. I see many posts suggesting the use of msysgit to enable the Git command line, and I also see many other tools that can work around it. But currently I just get the Git client tools for Windows from GitHub. Then I can use the git command in my windows command console. I don't know if it includes the msysgit in it.
The git client tools will include msysgit. You might need to add the git bin directory into your path for ssh to work correctly with cmd (and powershell)
Also, I would highly recommend "posh git" which is a powershell module that gives you some tab completion and a git prompt in powershell, if you are a windows person, its likely you are more comfortable scripting in PS than in bash, and posh git is great for that.
find instructions here on how to install it.
Note on Windows usage: you should use Git with the provided msysGit
shell (Unix style), it allows to use the complex lines of command
given in this book. If you need, for some reason, to use the native
Windows shell / command line console, you have to use double quotes
instead of simple quotes (for parameters with spaces in them) and you
must quote the parameters ending with the circumflex accent (^) if
they are last on the line, as it is a continuation symbol in Windows.
http://git-scm.com/book/en/Getting-Started-Installing-Git
Are you using the msygit shell?
I rarely touch shell scripts, we have another department who write them, so I have an understanding of writing them but no experience. However they all appear rather useless with my issue.
I am trying to execute some KornShell (ksh) scripts on a windows based machine using Cygwin- we use these to launch our Oracle WebLogic servers, now it simply will not execute. I used to be able to execute these exact same scripts fine on my old machine.
Now I have narrowed this down to the fact the 'magic number' or whatever it is at the start of the script where it specifies the script interpreter path:
i.e.:
#!/bin/ksh
if I change it to execute as a simple bash it works i.e:
#!/bin/sh
I went through checking the packages installed for cygwin - now the shells I installed are:
mksh MirdBSD KornShell
bash the bourne again shell
zsh z shell
Should I expect to see a ksh.exe in my cygwin/bin directory? there is a system file 'ksh' which I was making an assume somehow associates it with one of the other shell exes, like mksh.exe
I understand my explanation may well be naff. But that being said, any help would be very much appreciated.
Thanks.
I believe the MirBSD korn shell is called mksh. You can verify this and look for the correct path by typing
% which mksh
% which ksh
or if you have no which,
% type -p mksh
% type -p ksh
or if that fails too, check /etc/shells which should list all valid shells on a system:
% grep ksh /etc/shells
You need to put the full path after the #! line. It will probably be /bin/mksh, so your line needs to look like:
#!/bin/mksh
You've probably fixed it by now, but the answer was no, your Cygwin does not (yet) know about ksh.
I solved this problem by launching the cygwin setup in command-line mode with the -P ksh attribute (as described in http://www.ehow.com/how_8611406_install-ksh-cygwin.html).
You can run a ksh using a bat file
C:\cygwin\bin\dos2unix kshfilename.ksh
C:\cygwin\bin\bash kshfilename.ksh
Running a shell script through Cygwin on Windows
Install KornShell (ksh) into Cygwin by the following process:
Download: ksh.2012-08-06.cygwin.i386.gz
Install ksh via Cygwin setup.
Execture Cygwin setup.exe
Choose: Install from Local Directory
Select the ksh.2012-08-06.cygwin.i386.gz as the Local Package Directory.
Complete Cygwin setup.
Restart Cygwin.