Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment a bash script in a gitconfig alias

Tags:

git

bash

I have the following script in a .gitconfig alias:

[alias]
    vx = "!f() { # I want to put a comment here \
                 foo='foo'; \
                 bar='bar'; \
                 separator=': '; \
                 # Comment Here As well \
                 result="${foo}${separator}${bar}"; \
                 echo $result; \
             }; f" 

If works fine if I remove the comments. However, with the comments the script just fails to run. Do comments inside a gitconfig alias use an operator different from #?

like image 353
AngryHacker Avatar asked Sep 05 '26 11:09

AngryHacker


1 Answers

Run git config alias.vx and you will see the alias is printed as a long single line. You cannot insert a shell comment in the middle of a line — comments start with # and ends at end-of-line. Once bash sees # it ignores the rest of the line.

The only workaround I can think of is to insert dummy commands that contain quoted strings. Like : Text; (: is a no-op command in shells; see https://linux.die.net/man/1/bash, section "Shell Builtin Commands") or echo Comment >/dev/null;

[alias]
    vx = "!f() { : I want to put a comment here; \
                 foo='foo'; \
                 bar='bar'; \
                 separator=': '; \
                 : Comment Here As well; \
                 result="${foo}${separator}${bar}"; \
                 echo $result; \
             }; f"
like image 158
phd Avatar answered Sep 08 '26 04:09

phd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!