Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: while {some command does not exit = 1)



On Sun, Jun 2, 2013 at 9:24 PM, TJ Luoma <luomat@xxxxxxxxx> wrote:

> Here's what I have been doing:
>
> #!/bin/zsh -f
>
> EXIT=1
>
> while [ "$EXIT" = "1" ]
> do
>
>         drutil discinfo | fgrep -q 'Please insert a disc to get disc info.'
>
>         EXIT="$?"
>
>         FOO
>
> done
>

It should work to just write

while ! drutil discinfo | fgrep -q 'Please insert a disc to get disc info.'
do
    FOO
done

Except that the $? value of the pipeline is going to be the exit status of
fgrep, not of drutil.  I suspect that's what you meant, so FOO runs only
when a disc is present.  You can make this clearer by writing it as

while ! { drutil discinfo | fgrep -q 'Please insert a disc to get disc
info.' }
do
    FOO
done

Spaces around the "!" are important, especially if you're in a shell with
history enabled.


Messages sorted by: Reverse Date, Date, Thread, Author