0

I have added alias in my .gitconfig

  rnd      =  !sh -c \"git commit -m '$(curl -s http://whatthecommit.com/index.txt)'\" 

And now when I type

git add . && git commit rnd

I get an error sh: 1: Syntax error: Unterminated quoted string

user2950593
  • 9,233
  • 15
  • 67
  • 131
  • See https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings – xserrat Jan 28 '20 at 08:36

1 Answers1

1

You have your quoting backward a bit... you want to single-quote the command to run, pass that to sh, and use the backslash-quoted double quotes around your string expansion...

rnd = !sh -c 'git commit -m \"$(curl -s http://whatthecommit.com/index.txt)\"'

And also, just a note, in your question you call git commit rnd, but in reality, you would call this as git rnd.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
  • Inside single quotes, one does need not to escape doublt quotes. That is, `... 'git commit -m "$(curl ... index.txt)"'` should be just fine. – kostix Jan 20 '17 at 06:46
  • @kostix I tested this before I posted the answer, and the non-escaped quotes do not work. I assume this is because one more interpolation is performed along the way than one would expect. – Dan Lowe Jan 20 '17 at 14:37