[英]How to comment a bash script in a gitconfig alias
I have the following script in a.gitconfig alias:我在 a.gitconfig 别名中有以下脚本:
[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 #
? gitconfig 别名中的注释是否使用与#
不同的运算符?
Run git config alias.vx
and you will see the alias is printed as a long single line.运行git config alias.vx
,您将看到别名打印为长单行。 You cannot insert a shell comment in the middle of a line — comments start with #
and ends at end-of-line.您不能在一行中间插入 shell 注释 - 注释以#
开头并在行尾结束。 Once bash
sees #
it ignores the rest of the line.一旦bash
看到#
它就会忽略该行的 rest。
The only workaround I can think of is to insert dummy commands that contain quoted strings.我能想到的唯一解决方法是插入包含引号字符串的虚拟命令。 Like : Text;
喜欢: 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;
( :
是 shell 中的无操作命令;参见https://linux.die.net/man/1/bash ,“Shell 内置命令”部分)或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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.