如果我硬编码的过程,我想find并运行脚本a
脚本A
#!/bin/bash PROCESS=/System/Library/Frameworks/QuickLook.framework/Resources/quicklookd.app/Co number=$(ps aux | grep $PROCESS | wc -l) if [ $number -le 1 ] then echo "Nope - This seems NOT to be Running" exit 2 else if [ $number -ge 2 ] then echo "This seems to be Running" exit 0 fi fi
剧本给了我我期待的答案。
如果我像这样运行脚本/System/Library/Frameworks/QuickLook.framework/Resources/quicklookd.app/Co
即使我们把sakdjnsakjsakfndsdkjnf作为他们的争论,它总是会回来:“这似乎是跑步”?
#!/bin/bash number=$(ps aux | grep $1 | wc -l) if [ $number -le 1 ] then echo "Nope - This seems NOT to be Running" exit 2 else if [ $number -ge 2 ] then echo "This seems to be Running" exit 0 fi fi
怎么了?
grep定位在进程列表中。
使用pgrep来search一个进程。 就像是:
T=$(pgrep -f "$PROCESS") if test -z "$T" ; then ... else ... fi
应该做的伎俩。