Translating this shell command:
$> sh -c 'if [ 1 -eq 1 ]; then echo TRUE; else echo FALSE; fi'
TRUE
To this git alias in ~/.gitconfig:
[alias]
test = !sh -c 'if [ 1 -eq 1 ]; then echo TRUE; else echo FALSE; fi'
Results in:
$> git test
<output-omitted> Syntax error: Unterminated quoted string
PS: Don't want to map shell scripts to git aliases.
PS2: As @Cyrus and @CodeWizard have mentioned, one additional pair of quotes is needed to protect the alias definition against multiple levels of expansion. Nice trick to avoid semicolons provided by @choroba. Thanks everyone.
Another solution is to put it in a string:
[alias]
test = "!sh -c 'if [ 1 -eq 1 ]; then echo TRUE; else echo FALSE; fi'"
This will also work.

It seems semicolons have special meaning in .gitconfig. Fortunately, you can rewrite the command without semicolons:
[alias]
test = !sh -c '[ 1 -eq 2 ] && echo TRUE || echo FALSE '
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With