2014-10-28 95 views
1

我試圖在Ubuntu 14.04 LTS系統上安裝beanstalkd。似乎沒關係,除了以下是給我非零返回狀態。一旦發生這種情況,Vagrant會暫停,並且在沒有運行的病房之後還有其他腳本可以安裝。Bash腳本返回非零狀態

我已經試過

grep -q "START=yes" 
grep --quiet "START=yes" 
grep "START=yes" > /dev/null 

非似乎抑制GREP的輸出

echo -n "Checking /etc/default/beanstalkd for beanstalkd startup line   ... " 
if [ -f /etc/default/beanstalkd ]; then 
    echo -n "START=yes is" 
    grep "START=yes" /etc/default/beanstalkd > /dev/null 
    if [ $? = 0 ]; then 
     echo -n "..already present" 
    else 
     echo -n "START=yes" >> /etc/default/beanstalkd 
     echo -n "..Added to /etc/default/beanstalkd" 
    fi 
fi 
echo "Done!" 

結果:

==> default: Checking /etc/default/beanstalkd for beanstalkd startup line   ... 
==> default: START=yes is 
The SSH command responded with a non-zero exit status. Vagrant 
assumes that this means the command failed. The output for this command 
should be in the log above. Please read the output to determine what 
went wrong. 
+0

如果GNU,你必須有兩個破折號:'--quiet'。 – 2014-10-28 22:25:00

+0

你試過'grep -q'來壓制輸出嗎? – amphetamachine 2014-10-28 22:25:04

+2

@amphetamachine,原來的帖子說是的,他確實嘗試過。 – 2014-10-28 22:25:49

回答

1

的grep的以下調用將抑制所有 grep輸出(stderr和stdout)。沒有警告,沒有錯誤,什麼都沒有。

grep -q "START=yes" /etc/default/beanstalkd >/dev/null 2>&1 

如果您的查詢是關於if [ $? = 0 ]; then行預期不工作,你可以用這個替代它:

if grep -q "START=yes" /etc/default/beanstalkd >/dev/null 2>&1; then 
    # already present 
+0

你給出的第一行沒有壓制錯誤信息。我將嘗試將這個grep調用分解成一個腳本,最後調用'exit 0',並在第二個腳本中繼續我的其餘工作。 – Erik 2014-10-28 22:47:59

+0

我把它收回..你的第二行,結合'如果'效果很好!謝謝 – Erik 2014-10-28 22:53:47

相關問題