Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-05-2007, 05:07 PM   #1
Registered: Jun 2007
Location: UK
Distribution: openSUSE 10.2
Posts: 138

Rep: Reputation: 15
Question how do i get a shell script to run in the background?

ok, im new to linux , This may be the most easiest things to do, but how do i run a shell script in the background?

thanks in advance!
Old 07-05-2007, 05:39 PM   #2
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 165Reputation: 165
Use the & character when you start it up:
/path/to/your/script &
Old 07-05-2007, 05:40 PM   #3
Registered: Mar 2007
Location: Plymouth, UK
Distribution: Fedora Core, RHEL, Arch
Posts: 342

Rep: Reputation: 38
bash has built-in job control capabilities

You can put jobs in the foreground and background at will

To put a job in the background from the start, append an ampersand at the end of the command:


Bash replies with
[1] 27267

The number between the brackets is bash' job number, the number next to it is the process id

Armed with this number, you can now put the job in the foreground with the command

fg 1

This will bring the program to the foreground (provided it has not terminated), and attaches the stdin to the console.

To put this job back in the background, press Ctrl+d

Also, you may type the command


To get a list of all running jobs and their status:

[1]+ Running updatedb &

All this and more from the bash man page (man bash)
Old 07-05-2007, 06:11 PM   #4
Registered: Jun 2007
Location: UK
Distribution: openSUSE 10.2
Posts: 138

Original Poster
Rep: Reputation: 15

Thanks for your replies!, now i can get my startup script to work properly!
Old 07-06-2007, 02:28 AM   #5
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 199Reputation: 199
you can also use nohup which will keep it going when you close the terminal

also you can use batch or at

they are interactive though I usually do like this:

ls script | batch
echo script | at now + 10 minutes

the output is mailed to you on completion


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run a shell script in the perl script sharad Linux - General 1 05-24-2006 03:23 AM
verify if the same shell script is executing in background hicham007 Programming 2 08-07-2005 05:40 AM
How to run SHELL script pito Linux - Newbie 4 12-17-2004 03:05 AM
Shell script to run pl/sql script. colly Linux - General 1 09-09-2004 06:49 AM
How to run a bash command in the background from perl script professorfrink Programming 3 11-13-2003 03:02 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:58 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration