* while {some command does not exit = 1)
@ 2013-06-03 4:24 TJ Luoma
2013-06-03 5:05 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: TJ Luoma @ 2013-06-03 4:24 UTC (permalink / raw)
To: Zsh-Users List
I keep thinking that there must be an easier way to do this, but I
can't figure out what it would be, and Google has not helped.
I'm trying to create a "while" loop which will keep going as long as
some command does not exit = 0
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
exit 0
# EOF
(where 'FOO' is some command I want to run)
What I keep thinking I ought to be able to do is something like this
while ((! drutil discinfo | fgrep -q 'Please insert a disc to get disc info.' ))
do
FOO
done
I realize that "while (( ))" syntax is wrong, but I hope the idea is
clear. It appears that the | might be what is making this not work.
Is there an easier way to do this?
TjL
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: while {some command does not exit = 1)
2013-06-03 4:24 while {some command does not exit = 1) TJ Luoma
@ 2013-06-03 5:05 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2013-06-03 5:05 UTC (permalink / raw)
To: Zsh-Users List
[-- Attachment #1: Type: text/plain, Size: 821 bytes --]
On Sun, Jun 2, 2013 at 9:24 PM, TJ Luoma <luomat@gmail.com> 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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-06-03 5:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-03 4:24 while {some command does not exit = 1) TJ Luoma
2013-06-03 5:05 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).