[Nottingham] Re: AAaaargh! Bash and & and ; and () ...
Martin
martin at ml1.co.uk
Tue Jan 24 22:28:47 GMT 2006
And the LUG mailman is silly slow still.
Further details and observations below.
Martin wrote:
> After some very convoluted lost hours:
>
> I've likely rediscovered what many already know in that bash gets
> awfully confused when you try "&" at the end of a line with bracketed
> multiple commands and ";"!
>
> All on one line and things fail.
> Spread out onto one instruction per line (no ";" anywhere) so that you
> get a final ") &" all on its own and all works fine.
>
> I suspect that "()" or "{}" don't always protect the ";" effects.
>
> Time to try zsh I think!
>
> (OK, so there's also some file redirection and pipes implicated also.)
>
> AAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaargh!
> Martin
>
>
> (Sorry for the noise but that might be a useful bash tip for someone!)
The bash script that now works is:
( # sequence period timer
sleep $linterval
echo "$pn" >$sd/${lifn}.pipe
) & # Redirecting the output here breaks the "&" forming a
concurrent process! But works ok elsewhere!!
The "sleep" in there seems to be the culprit for breaking the
redirection or "&".
And that routine is paired with:
# Wait for the interval write
{
k='~'
# read -t 55 k <$sd/${lifn}.pipe # This line doesn't work!
read -t 55 k
# Check that this is the expected result!
[ "X$k" == "X$pn" ] || { echo "Lost interval pipe synch! Read
'$k', expected '$pn'." >&2 ; exit 1 ; }
} <$sd/${lifn}.pipe
A second strangeness there is that redirection on the read doesn't work
even though the 'Advanced bash manual' shows that it should.
Is there something 'strange' about redirecting named pipes?!
Enough hours and permutations to track those two down... I'll let others
puzzle that one through.
Have fun,
Martin
--
----------------
Martin Lomas
martin at ml1.co.uk
----------------
More information about the Nottingham
mailing list