3

I have a bash function that runs a few sub-processes in parallel, like this:

#!/bin/bash
function check() {
  set +m
  for f in foo bar ; do
    (
      if [ -f $f ] ; then ls -la $f >> all; fi
    ) &
  done
  wait
}

On sourcing and running this (. scriptfile; check), the +m has successfully suppressed job completion output, but it still shows process IDs on creation, like:

[1] 123
[2] 456

How could those ID lines be suppressed?

mahemoff
  • 44,526
  • 36
  • 160
  • 222

2 Answers2

2

Or even better, try to use gnu parallel to run all those processes in parallel.

something like:

parallel -P 5 'if [ -f {} ] ; then ls -la {} >> all' ::: foo bar
rsingh
  • 31
  • 2
2

Shell writes background process-id on stderr so one way of doing it is to suppress stderr inside your script:

#!/bin/bash
function check() {
  set +m
  for f in foo bar ; do
    {
      if [ -f $f ] ; then ls -la $f >> all; fi
    } &
  done 2>/dev/null
  wait
}
anubhava
  • 761,203
  • 64
  • 569
  • 643