Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

In particular, I created a script to start Firefox which I double-click and choose 'Run in terminal,' but when the shell exits Firefox is killed immediately.

How do I prevent this from happening?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

You need to put the nohup before the command that launch firefox, so it needs to looks like that:

>$ nohup firefox

share|improve this answer
Also executing bashrc in your script can set environment variables needed by Firefox or other programs. –  Garrett Hall Nov 30 '11 at 14:42
You can also use disown, a bash internal to achieve the same thing. This wont redirect output like nohup will but it can be used to orphan any long running jobs you started without the likes of nohup and you want to keep them running after you leave. –  Matthew Ife Nov 30 '11 at 18:38

Also Make sure you execute firefox as a background job and not as a front running since the shell is parent and is waiting for the firefox to run and exit before the prompt is to be returned.

share|improve this answer

Most solution what you find on the net, will run the firefox's script in a subshell. You will get the control back, after this subshell exits. If the firefox script runs in the background, you won't see its changes and variables set, and if its parent shell (your real shell) exits, it will probably still continue in the background.

The main reason behind that, that shells, including bash, have a make very clear difference between their

  • interactive modes: where they display prompt, read commands from the user, and execute them in a cycle.
  • and non-interactive modes: it this case, they are executing essentially as an interpreter language, interpreting a shell script.

There is no easy way to change bash from a non-interactive script mode to an interactive one, after a script execution (this time, the firefox starter/wrapper script).

It would be possible, but as I know, no shell has support for this.

Fortunately, there many tricky ways to reach your goal:

  1. You can run the non-interactive script as the initialization file of your bash. So: bash --bashrc /here/is/what/i/
  2. You can modify /here/is/what/i/ to re-execute its own interpreter, but this time already in interactive mode. This can be done with an exec /bin/bash -i command. Simply put this to the end of your script.
share|improve this answer

Your Answer


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.