.profile 函数在字符串连接中复制我的参数?

.profile function duplicates my argument in a string concat?

我使用 Git 提交问题编号与 GitHub 问题对齐。为了节省时间,我写了一个 bash 函数来创建这样的提交消息:

git commit -m "#4 my commit message"

调用时

gci 4 "my commit message"

其中 4 是问题编号,后面是提交消息。

但是,我当前的实现:

alias gcm='git commit -m '
gci(){
    index="${@:1}"
    message="#$index ${@:2}"
    gcm "$message"
}

两次生成提交消息:

$ gci 4 "my commit message"
[iss2 79d9540] #4 my commit message my commit message
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 h.z

是什么导致消息重复两次?

${@:1}${@:2} 没有按预期工作,第一个参数使用 </code>,第二个参数使用 <code>

alias gcm='git commit -m '
gci(){
    index=""
    message="#$index "
    gcm "$message"
}

附带说明一下,别名在非交互式 shell 中不起作用。
${@:1},来自 here

${var:pos}
Variable var expanded, starting from offset pos.

所以如果"$@" == "4 my commit message",那么:
"${@:1}" == " my commit message"
"${@:2}" == "my commit message"
当您连接 ${@:1} ${@:2} 时,您会看到我的提交消息两次。