I have to work with a command (lets call it update) which somehow prints its output asynchronously to the terminal (mq_timedsend). The output is not recognized as the commands output and therefore the stdout of the command is not usable (piping like update| grep -m 1 "$s" does not work). Unfortunately, I have to life with this.

Invoking the command sooner or later will print $s or $f as the creators were apparently also not aware of exit codes. I need to be able to parse after $s and $f and set the exit code manually.

I'm still not very versioned with bash and all its possibilities. How could a script or even a single chained command which will execute the update command and will wait until the specific text ($s or $f) appears in the console look like? Is this even possible?

closed as unclear what you're asking by andcoz, schily, Isaac, msp9011, maulinglawns Aug 22 '18 at 10:16

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Are you searching for literally $s in update output? What happens if you try update | grep -m 1 -F '$s'? – andcoz Aug 21 '18 at 12:16
  • Nothing, as the command update does not produce a direct output. It most possibly starts another background process which finally prints to the console. – Herr Derb Aug 21 '18 at 12:23
  • Perhaps update is using STDERR, try update 2>&1 | grep -m 1 -F '$s' – andcoz Aug 21 '18 at 14:04
  • no I'm afraid not. update &> log.txt results in an empty file while text is getting printed to the console, after the console was ready to take input again. – Herr Derb Aug 21 '18 at 15:28
  • 1
    You should find out what processes update creates and what file descriptors it writes to. Try with e.g. strace or similar. – RudiC Aug 21 '18 at 22:13