Daniel Hollands
Daniel Hollands

Reputation: 6671

automatically running a bash script in the background

I'm interested in finding out how I'm able to do the following, but automatically.

Right now I have a bash script that looks something like this:

#!/bin/sh
sass --watch htdocs/css/scss:htdocs/css --debug-info

Now, because I want to be able to run other command-line tasks at the same time as this script is running, I could just run it inside a new window, but I prefer to have it run as a background process, which I achieve by:

Which lets me continue to use the command-line, while also seeing the output from the sass command.

I'm also able to use jobs to see what's running, and finally, fg to bring the background script to the forefront, and use [ctrl] + [c] to cancel out of it.

All of which is fine, but it's a bit long-winded - is there any way that I can edit the bash script so it will automatically run in the background, similar to what I've described above?

Thank you

Upvotes: 0

Views: 1773

Answers (2)

tejaswi prakash
tejaswi prakash

Reputation: 124

An alternative to this , which I found useful is to write a function Foo(){ Do stuff }

and call the function and send it to the background

Foo &

All within the script, so you don't have to do

script.sh &

Instead, just invoking the script will send it to the background.

Upvotes: 0

Marc B
Marc B

Reputation: 360562

$ ./script &
           ^--- run script in background from the get-go

Upvotes: 3

Related Questions