using assist on Git Bash - windows

I use Windows 7.What is the correct way to use help in Git Bash?
help command
or
command --help
For example:
I have to use CTRLC to break result of below command
$ while --help
>
But this works:
$ help while
while: while COMMANDS; do COMMANDS; done
Expand and execute COMMANDS as long as the final command in the
`while' COMMANDS has an exit status of zero.
Or
$ help touch
sh.exe": help: no help topics match `touch'. Try `help help' or `man -k touch'
or `info touch'.
But
$ touch --help
Usage: touch [OPTION]... FILE...
or: touch [-acm] MMDDhhmm[YY] FILE... (obsolescent)
...
I looked at An A-Z Index of the Bash command line for Linux.But I do not find any thing in about using help command.

As mentioned in How to Get Help With a Command from the Linux Terminal, help is only for a short list of the commands built into the Bash shell itself. touch is not one of them.
For git commands, you would call git help <command> (like git help checkout).
Make sure to use git-bash.exe packaged with the latest release from git-for-windows: its bash is significantly more recent than the old msysgit one.
See "Why is it that if you download Git 2.0 from the net, you always get a 1.9.4 installer package?".

Related

Invoke "git bisect run <script>" from a shell script containing the bisect script, too

I working on Git now and having a big problem.
The command git bisect run needs to be like that:
$ git bisect run <my_script> $arguments
But I need to work with git bisect run only in one script.
I know that my solution with 2 scripts works but I can't find a way to combine them.
What can I do that will resolve the problem?
I tried to use:
git bisect run sh -c
As example: In working on git and writing: bash ../bisecter.sh 102. When bisecter.sh is the name of the script and 102 is something we need to search in the commits. And this script I'm trying to write. With bisect and bash commands.
You could check to see if the program is being run in "interactive mode" and run the appropriate command. If it's interactive, run git bisect. If it isn't, you're being run by git bisect.
An interactive shell is one started without non-option arguments (unless -s is
specified) and without the -c option whose standard input and error are both con-
nected to terminals (as determined by isatty(3)), or one started with the -i
option. PS1 is set and $- includes i if bash is interactive, allowing a shell
script or a startup file to test this state.
In bash you can check if file descriptor 1 (stdout) is outputting to a terminal.
if [ -t 1 ]; then
echo "We're run from a shell, run git-bisect"
else
echo "We're not run from a shell, do the bisecting."
fi
$ ./test.sh
We're run from a shell, run git-bisect
$ ./test.sh | cat
We're not run from a shell, do the bisecting.
But I seriously doubt that's what your professor intends you to do. The requirement to pass the same program to git bisect as runs git bisect doesn't make sense. Either the professor has an odd requirement, a distinct possibility, or perhaps you've misunderstood how to solve the problem.
When bisecter.sh is the name of the script and 102 is something we need to search in the commits.
git bisect is not for searching like that. It is for finding which commit caused a bug.
If you want to find which commit made a particular change, either in the log messages or in the changes, use git log -S or git log -G. That makes sense to do it in a single file.

Failing to run external Bash program — /usr/bin/bash: bad interpreter: No such file or directory

I'm trying to run a CLI tool in Linux (Mint) which allows me to edit subtitles. It is named subedit: github link. In order to run it, I've added executable permission with chmod +x and added it to the path in bash. However, when I run it, I get the following error message:
bash: /home/main/Documents/shellTools/subedit/subedit: /usr/bin/bash: bad interpreter: No such file or directory
I'm not very experienced with external bash programs and forgot to do something that would be obvious in hindsight.
When I do echo $PATH this is the output:
/home/main/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/main/Documents/shellTools/subedit/
Could somebody please help?
Assuming bash is installed, (it usually is), change the first line of subedit from:
#!/usr/bin/bash
to:
#!/bin/bash
Or if one would prefer not to edit subedit, try this one-liner covering what Al-waleed Shihadeh suggested:
ln -s "$(which bash)" /usr/bin/bash
It seems that you don't have bash installed, you can verify that by running
which bash
if the above command returns "bash not found", then you need to install it.
In case the above command returns a path, you can use the below command to add a symlink to the expected path
ln -s $(path from the above command) /usr/bin/bash
Use the command termux-chroot ONCE!
If you want to always run at the start of a session, be sure to check if it was never run before.
if [ -z $CHROOT ]; then
CHROOT=1
termux-chroot
fi

git command with command substitution doesn't return anything

bash: GNU bash, version 4.3.42(4)-release (x86_64-pc-msys)
OS: Windows7
git: git version 2.6.4.windows.1
Without command substitution, directly executing git commands would return correct answers.
$ git write-tree
76cb4719e27c7d77ef396992b3ba90cd98d22fcd
But when I execute some git commands with command substitution, it would return nothing.
$ echo "`git write-tree`"
$ echo "$(git write-tree)"
But the most strange thing is: Only some of git commmands occur this problem, for example: git write-tree, git rev-parse, git var. And other git commands, such as git log, run well.
And some environment is exactly as same as mine, OS, bash and git. But everything works fine.
As a result, I wanna konw whether there's something I need to configure. This thing really confuse me.
That must have been fixed in more recent version of Git for Windows.
Here is what I see with Git 2.18, in a bash session:
vonc#vonca:/mnt/d/git/tests/aa$ echo $(git write-tree)
4b825dc642cb6eb9a060e54bf8d69288fbee4904
vonc#vonca:/mnt/d/git/tests/aa$ echo "$(git write-tree)"
4b825dc642cb6eb9a060e54bf8d69288fbee4904
If the issue is still random, try making the same test using a CMD session with a simplified PATH, and launching the bash from said session.

Very basic git batch in Windows 7

Synopsis
Pass arguments to git bash using a .bat file
OR
Use git some other way by running a batch file.
Disclaimer
There are a lot of answers to similar questions out there, but having tried and failed most or all of them, I hope you don't smack me with a DUPLICATE stamp at first sight.
My system
Windows 7, 64 bit
git version 1.9.4.msysgit.2
The challenge
I want to rationalize my workflow from navigating to a number of git repos and running git status, git add --all etc, to simply run a batch.
Other posts certainly suggests it's possible. I think most of them use Unix, but this one at least got me up and running on Windows so I could test it out. However, I'm having the same problems as OP in that post when it comes to passing the commands to the git bash, and to a complete beginner like me it seems a bit complicated to use the suggestions from #Erik further down in the same post if you want to include more commands in the work flow.
Following the suggestions from #inf3rno in the same post, it seems I'm able to change folders but not able to use git commands like this:
set bash=C:\Program Files (x86)\Git\bin\bash.exe
"%bash%" --login -i -c "exec "%1""
cd c:\repos\research
git status
pause
Does anyone have suggestions as to how I can change the code above to get it working?
And by the way, what's the deal with #!bin\bash from other posts like this one? I assumed I had to use #!Program Files (x86)\Git\bin\bash, but I had no luck with that either...
Anyway, thank you for any suggestions!
First, uninstall git 1.9.4 (msygit, which is now obsolete): git-for-windows will offer a much recent bash (2013 vs. 2005).
Simply unzip PortableGit-2.6.1-64-bit.7z.exe anywhere you want, add C:\path\PortableGit-2.6.1-64-bit\bin to your %PATH% and you are good to go.
Second, inf3rno's answer is about executing any bash script ("%bash%" --login -i -c "exec "%1"": the %1 is the path/name of the bash script to be executed)
The right shebang to use in your bash scripts would be #!/bin/bash (see "What is the preferred Bash shebang?")
With the latest git 2.6, that would be:
c:\prgs\git\PortableGit-2.6.1-64-bit\bin\bash.exe --login -i -c "exec ./myscript"
Since that folder is supposed to be in your %PATH%:
bash --login -i -c "exec ./myscript"
With myscript being a file using Unix-style eol (LF), not Windows-style (CRLF)
Note also that any bash script (even on Windows) called git-myscript can be directly called with:
git myscript
I described in 2012 another approach in "Running a batch file in git shell" for executing git command.
But for a pure bash script, you will want to go with bash --login -i -c "exec ./myscript".
For writing bash scripts with unix eol style, you can choose various editor from Notepad++, SublimeText 3 or Atom.io.

Unable to successfully execute some commands in Cygwin

I installed Cygwin64 in my 64-bit Windows 7 machine. The following commands failed executing, however, by displaying the error messages below. Could you help providing a resolution please?
$ ll
-bash: ll: command not found
$ clear
-bash: clear: command not found
However, the command ls -l worked...
$ ls -l
total 0
Also i tried by un-commenting the following line in .bashrc file in my home dir -
# alias ll='ls -l'
But it didn't help either!
After you uncomment the alias, you should start a new Cygwin shell for it to take effect. The .bashrc file is actually a script that is sourced when bash starts.
clear is not a Cygwin (Unix) command. Just use Ctrl-L instead.

Resources