Results 1 to 7 of 7
I don't know much about scripting on my own, I would like to make a script that can be run from the terminal that would start 2 programs at once ...
- 07-09-2008 #1Just Joined!
- Join Date
- Jul 2008
- Posts
- 17
How to write a simple script to start 2 programs at once?
I don't know much about scripting on my own, I would like to make a script that can be run from the terminal that would start 2 programs at once for example "firefox" and "gimp".
The reason I need this is to run them both over an NX remote access session so that I don't have to use a full virtual desktop (which is slower).
Thanks for any help
NEVERMIND: I found this thread: two commands on 1 line - The UNIX and Linux Forums Sorry for not searching thoroughly enough before asking
- 07-09-2008 #2
So for the record, I don't believe that that thread answers your question. It is true that those answers allow you to start two programs on one line, but it is no different from starting two programs on two lines. Which is to say, it will start the GIMP, wait for you to close it, then start Firefox.
What I believe you want is to start the GIMP, then immediately start Firefox without waiting for the GIMP to be done. This is fairly simple:
Adding an '&' to the end of a command means "Run this command in the background". That means that you won't wait for it to finish before executing the next command.Code:#!/bin/bash gimp & firefox
I hope that this helps!DISTRO=Arch
Registered Linux User #388732
- 07-09-2008 #3Just Joined!
- Join Date
- Jul 2008
- Posts
- 17
Thanks for the response, you are right that the first code doesn't work, the second example they gave works:
gimp | firefox
- 07-09-2008 #4
Just to make things bit more clear,
Code 1:
Code 2 :Code:gimp | firefox
Code 2 works as Cabhan said runs a GIMP background process and you are started firefox without waiting for completion of GIMP command.Code:gimp & firefox
Code 1 and Code 2 are completely different.
In code1 ,
Output of GIMP is passed as an input of firefox.
So firefox will have to wait for an input which will be supplied by GIMP.
My intension is just to make sure ,
using & and | are completly two different things.
Hope this helps
Ps:I don't how to related GIMP and firefox- just take it as two separate process.
If i'm wrong please correct me.- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 07-09-2008 #5Just Joined!
- Join Date
- Jul 2008
- Posts
- 17
In Ubuntu the command: firefox | gimp starts both programs at the same time, so I'm not sure
- 07-10-2008 #6
It is correct that both are started simultaneously with the "|", but this is a different thing.
The '&' syntax that I gave is designed exactly for the purpose: to start multiple programs without one waiting for others.
The '|' syntax is called a pipe, and it turns output of one program into the input of another. In this case, it does start both simultaneously, but you will run into big problems with some programs. Piping is very powerful and lets you connect programs in new and exciting ways, but using it carelessly will mess with a lot of things. The starting simultaneously is actually a side-effect, not the actual purpose, and piping can be implemented without starting both simultaneously.
Because the '&' syntax was designed for this reason, I suggest you use it. It also makes your purpose a lot clearer if anyone else ever looks at your script.DISTRO=Arch
Registered Linux User #388732
- 07-10-2008 #7Just Joined!
- Join Date
- Jul 2008
- Posts
- 17
Thanks
that explains some programs mysteriously crashing my server, will use the & from now on


Reply With Quote
