0

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:

  • Hitting [ctrl] + [Z]
  • Running bg

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

1
  • use & at the end of comment Commented Feb 6, 2013 at 15:05

2 Answers 2

3
$ ./script &
           ^--- run script in background from the get-go
Sign up to request clarification or add additional context in comments.

1 Comment

I am just curious about the explanation line. I have seen it at SO sometimes, how did you make it? manually? or there is some "magic" to learn? (I have seen mutli-lines as well)
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.