2013-06-04 194 views
0

多字的文字。當我在寫一個shell腳本是這樣的:讀取命令行

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

read desc; 

git commit -m $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 

什麼是p與我的劇本一起嗎?

請建議的原因和解決方案來讀取命令行多字描述成變量$遞減

我已經嘗試使用:

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

read text; 

desc="'"$text"'"; 

git commit -m $desc; 

但是沒有用。

預先感謝您

+0

我試着用'git commit -m'$ desc''和'git commit -m'''$ desc'「''但它沒有用,爲什麼? – sivareddy963

回答

3

需要引用:

git commit -m "$desc" 

的區別是一個之間:

git commit -m hope it works 

git commit -m "hope it works" 

第一個嘗試提交文件itworks與消息hope,而後者提交的索引與消息hope it works

+0

謝謝你的工作..! – sivareddy963

+0

雅爲此目的,我用單引號,即'git commit -m'$ desc'' 另外我嘗試使用'git commit -m''''$ desc'''''' 但它沒有工作,爲什麼? – sivareddy963

+0

參數在單引號內不擴展。在第二種情況下,你並沒有引用'$ desc',所以它在shell甚至看起來是兩個單引號(每個單引號分別引用)之前仍然擴展爲單獨的單詞。 – chepner