/root/file hashttps://stackoverflow.comhttps://stackexchange.comhttps://reddit.comI need to open all these websites one after another in one firefox window only. Here is my code#!/bin/bashwhile read linedo     if pgrep firefox;     then         firefox --new-tab $line ;     else         firefox $line ;    fi done < /root/fileI tried nohup also but it didn't work.The problem is that if I use ; it would bind to shell process and won't run the next command until I exit out of firefox and if I use nohup or & , it would be separated from the shell and will open the new window of firefox instead of new tab. In both cases, every website opens in new window.Partially Solvedxdg-open opens websites in one window when commands are manually typed on the shell like$ xdg-open https://stackoverflow.com$ xdg-open https://stackexchange.com$ xdg-open https://reddit.combut it doesn't work in script. I have the following script with xdg-open#!/bin/bashwhile read linedo     xdg-open $linedone < /root/filebut it again opens websites in different windows instead single window.
Open multiple websites one after another in one firefox window only
shell script;firefox
Your problem here is that it takes some time for Firefox to start. If you run it in the background, next time you do firefox --new-tab, your first instance has not quite started and is not ready to open another tab. You must wait some time after starting the first Firefox instance:#!/bin/bashwhile read linedo    if pgrep -u $USER firefox > /dev/null    then        firefox --new-tab $line &    else        firefox $line &        sleep 3                 # You may want to tune this value    fi < /dev/nulldone < /root/fileBeware that with this kind of construct any program in your loop may eat what comes from stdin and this will end your loop prematurely. That's why I have preventively added < /dev/null to the if part.