[英]In Ubuntu, how might I from the terminal open application only if it's not already running?
I'm using a basic script to open up the apps I need for development and I have to open an editor, but only if it's not already running. 我正在使用基本脚本打开我需要开发的应用程序,我必须打开一个编辑器,但前提是它还没有运行。
How can I first determine if sublime is up before running the application as follows: 如何在运行应用程序之前首先确定sublime是否已启动,如下所示:
subl <filename>
我认为你总是可以通过'ps ax | grep'确定它运行,对吗?
I think I've got one solution: 我想我有一个解决方案:
SERVICE=$1
if [ `pgrep $SERVICE` ]
then
echo "$SERVICE is running."
else
echo "$SERVICE is not running."
fi
You might want to have a look at ps
? 你可能想看一下ps
?
if [[ $(ps -e | grep "the thing you want") -ne 0 ]]
#checks if there is anything returned
then
subl <filename>
fi
This correctness will be based on how "exact" you search... 这种正确性将取决于您搜索“精确”的程度......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.