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