0

I want to see the backgrounded jobs when inside a bash script. Is this possible? To illustrate I run the command /usr/bin/experiment here but end up with no output.

$ cat /usr/bin/experiment
#!/bin/bash
echo $(jobs)

$ watch ls

[1]+  Stopped                 watch ls
$ /usr/bin/experiment

$ 
american-ninja-warrior
  • 7,397
  • 11
  • 46
  • 80

1 Answers1

0

Your script launches a new shell, which does not see the active jobs of the original shell.

If you run your script as follows:

source /usr/bin/experiment

you will get the output you are looking for

EJK
  • 12,332
  • 3
  • 38
  • 55