Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have created a bash script that starts an application. Since I wanted the terminal window to close when the application is started, I used this line:

firefox & 2> /dev/null; exit;

It works fine as long as I start the script from the command line. However, if I start it from a desktop laucher the application closes as well as the terminal. Can anyone explain why this is. Im using Ubuntu 10.10.

By only using:

    nohup firefox

it works. But I still would like an explanation to why the original version doesn't work when started from a desktop launcher, if possible.

share|improve this question

3 Answers 3

Try the nohup-command:

nohup firefox & 2> /dev/null; exit;

nohup disconnects the running jobs from the terminal session which prevents them from being closed on exit.

However, if you only want to start firefox, then simply create a shortcut to it, no bash script required.

Further as explanation: Try to run the script from a terminal, leave the firefox window open and close the terminal in which you ran your script. Firefox will close as well as it is a child process of the terminal session it was started from.

share|improve this answer
    
Thanks but no difference when using nohup. I use a script because ther are other things happening before starting the app, but this is the only line not working. (It does work when started from command line.) –  Lars Jan 9 '12 at 8:53
    
does it work even when you close the terminal (command line) after starting your script? –  Michael K Jan 9 '12 at 9:37
    
Yes, perfectly so. It only fails when started from a desktop launcher. –  Lars Jan 9 '12 at 10:25
    
If you would like help with a script, please post the entire script for review. –  bodhi.zazen Jan 9 '12 at 17:42
up vote 3 down vote accepted

The solution is to simply use the right form in the pipe:

firefox > /dev/null 2>&1
exit

This works both from terminal and from a desktop launcher. No need to use nohup.

share|improve this answer

A solution that worked for me is to put a 1 sec sleep into the script.

Here is a minimal example of the script I was trying to run via a gnome desktop launcher:

#!/bin/bash
echo "test"
read e

nohup firefox & 2> /dev/null
exit

This works fine when started from within a terminal, i.e.:

  1. it displays "test" and after pressing enter firefox starts
  2. firefox stays alive when closing the terminal

However, when starting this from a desktop launcher with:

gnome-terminal -e "script"

a terminal displays "test" and shuts down after pressing enter (firefox never shows up, I assume it is killed with the terminal).

However the following works started with a launcher:

#!/bin/bash
echo "test"
read e

nohup firefox & 2> /dev/null
sleep 1
exit

in this case firefox starts after pressing enter, and stays alive when the terminal shuts down after the sleep time (or is closed during the sleep time).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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