Reputation: 153
When I'm writing a shell script like this:
echo -n 'Enter description of new version: ';
read desc;
git commit -m $desc;
and when I'm entering multi word description, then it is taking only one word into $desc and giving me errors as:
Enter description of new version: hope it works
error: pathspec 'it' did not match any file(s) known to git.
error: pathspec 'works'' did not match any file(s) known to git.
fatal: too many params
and sometimes it is giving like:
Enter description of new version: final check
error: pathspec 'check'' did not match any file(s) known to git.
fatal: Failed to resolve 'check'' as a valid ref.
Everything up-to-date
What is the problem with my script?
Please suggest the cause and solution to read multi word description from command-line into the variable $desc
I've tried using:
echo -n 'Enter description of new version: ';
read text;
desc="'"$text"'";
git commit -m $desc;
But no use.
Thank you in advance
Upvotes: 0
Views: 97
Reputation: 26555
You need to quote:
git commit -m "$desc"
The difference is the one between:
git commit -m hope it works
and
git commit -m "hope it works"
The first tries to commit the files it
and works
with the message hope
, while the latter commits the index with the message hope it works
.
Upvotes: 3