如何在gitconfig别名中注释bash脚本 [英] How to comment a bash script in a gitconfig alias
问题描述
我在.gitconfig别名中有以下脚本:
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"
如果删除评论,效果很好.但是,带有注释的脚本只是无法运行.gitconfig别名中的注释是否使用不同于#
的运算符?
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 #
?
推荐答案
运行 git config alias.vx
,您将看到别名打印为长单行.您不能在行的中间插入shell注释-注释以#
开头并在行尾结束.一旦 bash
看到#
,它将忽略该行的其余部分.
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.
我能想到的唯一解决方法是插入包含带引号的字符串的虚拟命令.像:Text;
(:
是shell中的无操作命令;请参阅 echo注释>/dev/null;
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"
这篇关于如何在gitconfig别名中注释bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!