Problem is:
grep the output of ps aux for any instance of firefox, if firefox is already running, open link in new tab, if firefox is not running, start firefox and open the link.
Point to be noted here is that I have mentioned the count variable to be greater than 1 because ps aux | grep firefox itself is a process that would be listed, so any other instance other than that. When I run the following script it, goes into loop, what's the right logic?
#!/bin/bash
count=0
while [[ $(ps aux | grep firefox) ]]
do
count=$((count+1)) ;
if ( count -gt 1 )
then
nohup firefox --new-tab "mega.nz" &
else
nohup firefox "mega.nz" &
fi
done
Edit : Thanks to the comments and answer below, they helped me get rid of the while loop totally by using pgrep as thrig and Deathgrip mentioned below, but how do I achieve this by while loop or let me know if this cannot be performed with while loop.
pgrepcan profitably replaceps ... | grep ...– thrig Jul 05 '17 at 19:06firefoxprocess, incrementingcount, and either running a newfirefox(first iteration), or opening a new tab (remaining iterations). Perhaps describe what you want to happen? – Deathgrip Jul 05 '17 at 19:30ps aux | grep --firefox, now from the output, if firefox exists in more than 1 processes (2 or more lines on terminal), run theifloop and exit out ofwhileloop – GypsyCosmonaut Jul 05 '17 at 19:33