bash, 使用字符串的脚本

bash, script for using string

我想在一行中执行 2 个命令:

git add filename
git commit -m "A message"

我正在尝试这个:

#!/bin/sh
if [ "$#" -ne 2 ]; then
  echo "Usage: ./gac FILENAME COMMIT_MESSAGE" >&2
  exit 1
fi
git add 
git commit -m 

但我的问题是我必须将所有 COMMIT_MESSAGE 写在一起,不能有空格。我该如何解决?

我想像这样使用脚本:

gac filename "my message with spaces and double quotes"

尝试像这样引用 </code></p> <pre><code>#!/bin/sh if [ "$#" -ne 2 ]; then echo "Usage: ./gac FILENAME COMMIT_MESSAGE" >&2 exit 1 fi git add git commit -m "" # <-- here