Git Bash shell没有以我期望的方式接受这些参数?

Git Bash shell没有以我期望的方式接受这些参数?,git,bash,shell,Git,Bash,Shell,我运行下面的脚本 推式回购“消息” 但是,如果我的消息中有空格,脚本将中断。显然,解释器会将任何空格视为新参数的指示。如何更改行为,以便使用空格编写完整的提交消息 push() { local a=$1 b=$2 if [ $# -eq 0 ] then echo "Enter git shortname for first argument" return fi if [ $# -eq 1 ] then b=$(timestamp)

我运行下面的脚本

推式回购“消息”

但是,如果我的消息中有空格,脚本将中断。显然,解释器会将任何空格视为新参数的指示。如何更改行为,以便使用空格编写完整的提交消息

push() {
  local a=$1 b=$2
  if [ $# -eq 0 ]
  then
     echo "Enter git shortname for first argument"
     return
  fi

  if [ $# -eq 1 ]
  then
      b=$(timestamp)
  fi
  build
  git add -A .
  git commit -m $b
  git push $a
  echo "push() completed."
}

在函数中使用适当的引用:

push() {
  local a="$1" b="$2"
  if [ $# -eq 0 ]
  then
     echo "Enter git shortname for first argument"
     return
  fi

  if [ $# -eq 1 ]
  then
      b=$(timestamp)
  fi
  build
  git add -A .
  git commit -m "$b"
  git push "$a"
  echo "push() completed."
}

可能与我从未在任何其他语言中引用过的变量重复,人们会如何理解?是的,Unix shell在使用引号和不使用引号时的行为非常不同。@cadegalt您可以在Bash手册中阅读。