Skip to main content
2 of 2
edited tags
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k

passing string containing spaces as command-line argument from within script

I'm using a bash shell on mac.

I want to write a shell script 'gac' such that running

> gac one two three 

produces exactly the same effect as running

> git add . > git commit -m "one two three" 

So far my script is this:

function gac() { git add . concatenated="'$*'" git commit -m "$concatenated" } 

I found the trick for concatenating the shell arguments into a single space-separated string (second line of script) here. The above script almost works, except that the log message reads

a382806 'one two three' 

when I use my shell script, instead of

a382806 one two three 

as when I manually type in

> git commit -m "one two three" 

on the command line.

Any ideas?

Labrador
  • 171
  • 1
  • 1
  • 4