I am writing a quick start shell script to automatically set up my development environment for a current project. However, none of the commands in the shell script can be executed after my server starts because it takes over the terminal. I am trying to open a new tab, start the server in there and then continue executing my shell script in the original tab. My script currently looks like this:

subl myProj
cd myProj
gnome-terminal --tab
npm start
google-chrome http://localhost:3000

myProj ends up opening in the new tab and the server starts in the original tab. chrome never launches.

  • Adding to Serg's answer: you probably want those programs to not be bounded to the terminal. Look into bash's disown built-in (to be used in conjunction with &) an into the nohup command – kos Aug 27 '15 at 20:45
  • i'll take a look at those, but if they make the server run as a daemon and free up the terminal, it's not what i'm looking for. This is for my dev envrionment and I need the output I get from the server in the terminal. – user137717 Aug 27 '15 at 20:48
  • Well using & to put the process into the background also inhibits stdout / stderr, so you probably want to start the server at the end of the script. If not possible however you may still start it where you need it to start backgrounding it with &, start everything else with & + disown/ nohup and then put it into the foreground again using the fg built-in – kos Aug 27 '15 at 21:01
  • @kos can you elaborate on how it inhibits stdout / stderr ? I just tried a few operations and the output seems normal. Does it only inhibit output under certain conditions? – user137717 Aug 27 '15 at 21:08
  • I guess it does. Then it must be program-dependent. watch -n 1 echo foo &, for one, suppresses output. Not sure about what this depends on tough. – kos Aug 27 '15 at 21:16

Scripts execute commands in sequence, and wait until each command finishes. However, there is a way to allow the script to continue executing past a specific command - add & on the end of the script.

For instance:

echo "Next line"

Will wait till firefox is closed.

firefox &
echo "Next line"

Will execute echo command and allow keeping firefox open

  • Short and precise =) – A.B. Aug 28 '15 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.