if pgrep apache; then echo "oliver"; fioliverコマンドpgrep apacheが空でない場合、
これはエコーします。逆にやりたい。pgrep apacheコマンドが空の文字列を返す場合は、コマンドを実行します。
3 に答える
4
if ! pgrep apache; then echo "oliver"; fi
于 2013-02-18T19:18:15.063 に答える
1
これをやってみてください:
pgrep &>/dev/null apache || echo "foobar"
また :
if ! pgrep &>/dev/null apache; then echo "foobar"; fi
!NOTの略
これはコマンドの出力に基づくものではありませんが、コマンドが whastrueまたはfalse.
シェルでは、コマンドの戻りコードが の場合は0と見なされtrue、0 より大きい場合はと見なされfalseます。この戻りコードは変数$?で確認できます。例:
ls /path/to/inexistant/file
echo $?
真と偽のコマンドを見る
于 2013-02-18T19:15:31.170 に答える
1
I'm unsure of the context but presuming you want to do something a particular process is or is not found.
bash-3.2$ pgrep -q bash && echo "bash was found"
bash was found
bash-3.2$ pgrep -q XXXbash || echo "XXXbash was NOT was found"
XXXbash was NOT was found
于 2013-02-18T20:41:43.103 に答える