0

Consider the following scripts

#!/bin/bash
# fee.sh
echo "fee"

#!/bin/bash
# foo.sh
echo "foo"
./fee.sh &

Now execute the foo script.

$ ./foo.sh
foo

Only the output from foo.sh is visible. The output from fee.sh, which is spawned within foo.sh, is not visible.

tcamuso
  • 1
  • 2
  • Does your `foo.sh` script only contains these lines? You didn't play with `exec` in your terminal don't you? – Fravadona Nov 17 '21 at 21:52
  • Yes. All I want is to see the output from the "echo" in real time, not after the spawned process has executed. – tcamuso Nov 18 '21 at 16:02
  • 2
    Well, spawned processes will write to the terminal in real time by default, so I couldn't reproduce the issue with your example. – Fravadona Nov 18 '21 at 16:45
  • Interesting. I cannot see any real time output from the spawned process. I don't see any output until the process ends. Even then the screen doesn't do anything until I press RETURN. Then I finally get the output and the status returned by the spawned process. – tcamuso Nov 18 '21 at 17:02
  • Maybe your unspecified process, which is more complex than shown, is suffering from buffering. – Mark Setchell Nov 18 '21 at 17:08
  • Ah. Wait. My problem is that I am trying to get the output of a subprocess of a process. So, I have edited my original post to correctly reflect that. – tcamuso Nov 18 '21 at 17:10
  • No problem, I get `foo` `fee` with bash 3 & 4. You must something muting the output in your script. – Fravadona Nov 18 '21 at 17:39
  • When I execute './foo.sh', I only see "foo", I don't see "fee". – tcamuso Nov 18 '21 at 18:20
  • First you say "The output from fee.sh… is not visible", then you say "I finally get the output". Don't make contradictory or incomplete statements. – Armali Nov 19 '21 at 13:02

1 Answers1

0

I think you mean this:

set -b
sleep 3 &

Check out help set.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Well, no, that won't do. I'm actually doing something more complex than just "echo foo". I just used that as an example. What I want is to get real time output from a spawned process, rather than waiting for it to end and just getting a status or tailing a log file. – tcamuso Nov 18 '21 at 16:02
  • What do you feel is the difference between *"real time output"* and tailing a log file please? – Mark Setchell Nov 18 '21 at 16:11
  • 1
    "real time output" appears on the screen as the process is executing. Tailing a log file means that the user must do ... ``` $ tail /var/log/messages ``` ... in order to see output from the process. – tcamuso Nov 18 '21 at 16:49