2011-07-25 18 views
0

這裏是我的腳本:如何使用`read`中的變量作爲另一個程序的參數?

read -p 'commit message: ' msg 
svn status | grep ^\? | awk '{ print $2 }' | egrep "\.(py|js|html|png|jpg)$" | xargs svn add 
svn ci -m "$msg" 

當我運行它,但是,我得到這個錯誤:

[email protected]:~/myproject$ ./commit.sh 
commit message: test 
svn: Try 'svn help' for more info 
svn: Not enough arguments provided 

我真的不知道很多關於shell編程。消息沒有正確傳遞給svn ci或什麼?我怎樣才能使它工作?


[email protected]:~/myproject$ bash -x commit.sh 
+ read -p 'commit message: ' msg 
commit message: hello world 
+ egrep '\.(py|js|html|png|jpg)$' 
+ xargs svn add 
+ awk '{ print $2 }' 
+ grep '^?' 
+ svn status 
svn: Try 'svn help' for more info 
svn: Not enough arguments provided 
+ svn ci -m 'hello world' 

回答

2

的SVN CI線似乎罰款。你可以試着用bash -x來運行它,看看錯誤在哪裏:

$ bash -x commit.sh 
+0

啊......不知道那個。看來問題是沒有什麼可以添加的,因爲我已經跑了幾次。如果他們以前的查詢沒有找到任何東西,有沒有辦法可以跳過'svn add'? – mpen

+0

您可以根據svn狀態的返回碼將這些行分隔爲一個if塊。 $?總是有前一個命令的返回碼。 – jman

+0

哦!很酷。我會在稍後嘗試。謝謝! – mpen

相關問題