Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script: Suppress job creation message

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?

like image 763
mahemoff Avatar asked Jul 14 '26 13:07

mahemoff


1 Answers

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
}
like image 135
anubhava Avatar answered Jul 20 '26 18:07

anubhava