help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading a job name from deallocated storage


From: Greg Wooledge
Subject: Re: reading a job name from deallocated storage
Date: Thu, 3 Mar 2022 11:01:19 -0500

On Fri, Mar 04, 2022 at 02:39:41AM +1100, G. Branden Robinson wrote:
> 
> output=$("$preconv" -d "$device" 2>&1) &
> # If we've gotten _any_ output, assume it's enough, instead of lamely
> # sleeping for 1 second or similar.  If none, busy-wait on it.
> while ! echo "$output" | grep -q .
> do
>     :
> done

I'm not sure how to reproduce the issue you mentioned, but this part
of your script stood out for a different reason.  You're running the
assignment to 'output' as a background job, so the foreground part
of the script is never going to see any content in the 'output' variable.

unicorn:~$ output=$(echo stuff) &
[1] 2131318
unicorn:~$ 
[1]+  Done                    output=$(echo stuff)
unicorn:~$ echo "$output"

unicorn:~$ 

If you want the foreground part of a script to see the output of a
background process, you need to redirect it to a file, or something
equivalent.

Also, your script has a #!/bin/sh shebang.  Make sure you're actually
running it in bash, not dash.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]