0

I want to execute 2 commands in one line:

git add filename
git commit -m "A message"

I'm trying this:

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

But my problem is I have to write all the COMMIT_MESSAGE together, without spaces. How can I fix it?

I want ot use the script like this:

gac filename "my message with spaces and double quotes"
pmiranda
  • 7,602
  • 14
  • 72
  • 155

1 Answers1

0

Try qouting the $2 like so

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