Reputation: 624
I wish to write a bash script such that it launches Symfony built-in Web Server, hence Firefox. The following simple minded script fails because - I am not sure how to describe it by the correct jargon - the shell gets busy by the first task. I guess it is simple, but I am newbie on this. Thanks.
#!/bin/bash
cd /var/www/mySymfonyProj
php bin/console server:run localhost:8080
/usr/bin/firefox http://localhost:8080
Upvotes: 1
Views: 2428
Reputation: 6037
(moved comment to answer in order to "resolve" the question).
Add an &
after the 4th line of the script to run that process in the background - the shell will launch that process, and move onto the next line (but will wait for the 5th line's command to finish).
At the end of the script, you may want to call wait
to wait for the server to terminate, if that's desired.
#!/bin/bash
cd /var/www/mySymfonyProj
php bin/console server:run localhost:8080 &
/usr/bin/firefox http://localhost:8080
wait
For more information on job control, look at this source. It doesn't cover everything useful, but it covers a fair amount.
I'd mention that $!
returns the PID of the process just executed, so you can keep track of the PIDs of various background tasks then use wait
to delay until they've returned - that's often useful.
Upvotes: 3