检查字符串是否在字符串Bash中

时间:2017-10-16 18:11:31

标签: linux bash shell

我有这个bash脚本将运行Xvfb我需要检查它是否已安装或是否需要删除文件:

#!/usr/bin/env bash

DOESNT_EXIST="bash: /usr/bin/Xvfb: No such file or directory"
EXISTS="Fatal server error:"
RESULT="$(Xvfb | awk '{print $1}')"

if ${RESULT} =~ .*${DOESNT_EXIST}.* ; then
  sudo apt-get install xvfb
elif ${RESULT} =~ .*${EXISTS}.* ; then
  sudo rm -rf /tmp/.X0-lock
  sudo apt-get purge xvfb
  sudo apt-get install xvfb
fi

当我运行时,我得到以下输出:

(EE) 
Fatal server error:
(EE) Server is already active for display 0
        If this server is no longer running, remove /tmp/.X0-lock
        and start again.
(EE) 
etc/scripts/fix_pie.sh: 7: etc/scripts/fix_pie.sh: =~: not found
etc/scripts/fix_pie.sh: 9: etc/scripts/fix_pie.sh: =~: not found

我不明白这里有什么问题,我怎么能解决这个问题呢?

0 个答案:

没有答案