2014-10-28 98 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

相关问题