Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

l0uismustdie

macrumors regular
Original poster
Nov 30, 2009
109
1
Edinburgh, UK
Hello, I've come up with a command which will list all the background processes running in my current shell and am trying to run it from a shell script but am experiencing some difficulty. The script looks as follows:
Code:
#! /bin/sh                                                                      
jobs -l | grep -o '[0-9]* ' | xargs -E eofstr kill -9

If I run this line directly in my terminal it works fine but if I try to execute from the script it doesn't seem to do anything.

Any ideas?

Thanks.
 
The jobs command shows the processes that have been started in the current shell. When you run it in a script it is in a new shell and not aware of the jobs in the parent shell.
 
im not sure what you mean by 'create an alias'. And how could I use this to solve the problem. Thanks for responding!

As willieva mentioned, your script will run in a new shell. By creating an alias you can substitute the line you have with one identifier. Since this is just an alias, it will run in your current shell.

Code:
$ alias greetings='echo "hello"'
$ greetings
hello
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.