从命令行读取多字文本

时间:2013-06-04 13:12:30

标签: git shell command-line stdin

当我写这样的shell脚本时:

echo -n 'Enter description of new version: ';

read desc;

git commit -m $desc;

当我输入多字描述时,它只需要一个字进入$ desc 并给我错误:

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

有时它会给出:

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

我的脚本有什么问题?

请建议从命令行读取多字描述到变量$ desc

的原因和解决方案

我尝试过使用:

echo -n 'Enter description of new version: ';

read text;

desc="'"$text"'";

git commit -m $desc;

但没用。

提前谢谢

1 个答案:

答案 0 :(得分:3)

你需要引用:

git commit -m "$desc"

区别在于:

git commit -m hope it works

git commit -m "hope it works"

第一个尝试使用消息it提交文件workshope,而后者使用消息hope it works提交索引。

相关问题