PDA

View Full Version : [SOLVED] newbie bash questiong



MacHaddock
March 27th, 2010, 01:03 AM
I'm trying to maka a script that launches firefox and then evolution

so far I've got


#!/bin/bash

firefox

evolutionBut that doesn't work. It just starts firefox and then evolution as I close firefox.

I know that typing firefox -t in a terminal opens it as a seperate thread or whatever but I can't get that to work in the script.

How would you do it?

dwarfolo
March 27th, 2010, 01:06 AM
Try adding an "&" at the end of each line

#!/bin/bash

firefox &

evolution &

snova
March 27th, 2010, 01:10 AM
I'm trying to maka a script that launches firefox and then evolution

so far I've got


#!/bin/bash

firefox

evolutionBut that doesn't work. It just starts firefox and then evolution as I close firefox.

I know that typing firefox -t in a terminal opens it as a seperate thread or whatever but I can't get that to work in the script.

How would you do it?

Run firefox in the background:


firefox &

I am not certain what would happen if you ran both processes in the background though.

dwarfolo
March 27th, 2010, 01:24 AM
Well, sending both the commands in background let you close the terminal without waiting for them to return. You can send several command in the background at a time, but obviously if you close the starting shell you loose the option to use bg, fg and ctrl+z to control the jobs.

MacHaddock
March 27th, 2010, 12:00 PM
Well I don't know what those do anyway :D

The & was what I was looking for. Thanks a lot

now maybe there is a way to close the terminal as well with a command. I'm making a panel launcher that launches two programs by the way.

Barriehie
March 28th, 2010, 08:23 AM
$$ is the PID of the running process so to kill your launching terminal we use kill and send the process a signal 9, which can't be blocked. See the manpage of kill and it will tell you about the diff. signals. Also can't kill it without detaching the programs you're spawning and still have them run so we use the terminal to launch an instance of bash and give it a command with the -c 'string' and run in the background.



#!/bin/bash
bash -c 'firefox &'
bash -c 'thunderbird &'
kill -s 9 $$

MacHaddock
March 28th, 2010, 10:08 AM
That worked if I run it from the panel launcher which is what I want. Thanks!

can't say I understand why it doesn't work if i run it from a terminal though. but what the hey.

Barriehie
March 28th, 2010, 03:21 PM
That worked if I run it from the panel launcher which is what I want. Thanks!

can't say I understand why it doesn't work if i run it from a terminal though. but what the hey.

From an already open term:


bash -c name_of_script &