I am trying to write a quick bash script to automatically git push to multiple branches at once. My issue is, when I enter my commit message as a read variable, bash and git freak out at the use of whitespace.
Here is my current script:
#!/bin/bash
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "Pushing To all branches"
echo "What is your Commit Message?"
read message
git add *
git commit -m \"$message\"
git push origin
.... (push to other branches) ...
echo "Done!"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
And this works perfectly if my commit message is only one word. However, this is often not the case. For example, if I enter:
Testing test case
as my commit message, I would get the following errors:
error: pathspec 'test"' did not match any file(s) known to git.
error: pathspec 'case"' did not match any file(s) known to git.
Does anyone have any ideas on how to fix this so that my bash script can handle whitespace?
Thanks so much!
$message
causing it to perform word splitting. – jesse_b May 07 '18 at 02:43