how to control a shell script loop with: 'dpkg -s pv | grep Status'
编码处女需要帮助 - 一旦安装了包pv,这段代码总是
1 2 3 4 5 6 7 8 9 10 11 | # First check if pv package is installed, if not, install it first PACKAGESTATUS=`dpkg -s pv | grep Status`; if [[ $PACKAGESTATUS == S* ]] then echo"Package 'pv' is installed." else echo"Package 'pv' is NOT installed." echo"Installing package 'pv'. Please wait..." apt-get -y install pv fi |
它是备份脚本的一部分,备份运行Raspbian wheezy
谢谢。
由于双重'然后',因此在chepners答案中存在轻微的语法错误。
我对这个版本好运
1 2 3 4 5 6 7 8 | if `dpkg -s pv | grep -q Status;` then echo"Package 'pv' is installed." else echo"Package 'pv' is NOT installed." echo"Installing package 'pv'. Please wait..." apt-get -y install pv fi |
而不是捕获
1 2 3 4 5 6 7 8 | if dpkg -s pv | grep -q Status; then then echo"Package 'pv' is installed." else echo"Package 'pv' is NOT installed." echo"Installing package 'pv'. Please wait..." apt-get -y install pv fi |