4

Lets define a shell function (here the shell is Bash) and test it

$ s () { xterm -e sleep 5 & }
$ s
[1] 307926
$ 
[1]+  Done                    xterm -e sleep 5
$ 

With my specific meaning of better, I can redefine s like this

$ s () { xterm -e sleep 5 & disown ; }
$ s
[1] 307932
$ 
$ 

(no message from the shell when the job is finished).

Here I have to ask, is it possible to define s so that I have

$ s () { pre_magic xterm -e sleep 5 post_magic ; }
$ s
$ 
$ 

i.e., suppress the job info printed on terminal by the shell?

0

1 Answer 1

8

One approach is to wrap the call in a subshell effectively forcing all the unwanted job control output to be handled by a headless subshell. The key is to insure the & is inside the subshell wrapper, eg:

$ s () { ( xterm -e sleep 5 & ) }
$ s
$ 
4
  • 1
    Nice! Note that it still prints out stderr messages from xterm though. On my system, launching xterm spews out xterm: cannot load font "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1", and that message still appears. I suspect that is desired though since it is an actual error.
    – terdon
    Commented Apr 17 at 14:27
  • 1
    yeah, I was on the fence about going a bit further and addressing stdout/stderr (display or mask/hide?) and opted not to muddle the answer; a web search brings up this answer which points out that with this approach you lose job control and then the answer proceeds to provide some (convoluted) solutions and limitations on maintaining job control while masking the job control messages ... probably way more than OP is looking for in this case ...
    – markp-fuso
    Commented Apr 17 at 14:37
  • I have already accepted your answer, so feel free to ignore me… ;-) Another option is to set -m inside the function definition, do you feel/know that one solution (i.e., set -m ; ... & vs ( ... & )) is better than the other?
    – gboffi
    Commented Apr 18 at 9:36
  • see that link in my previous comment where set -m is addressed, including some side effects; personally, I tend away from set ... options because I (almost) always forget to undo the set and end up with unexpected results later in the session ;-)
    – markp-fuso
    Commented Apr 18 at 16:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.