Re: помогите с bash и условием
Peter Pentchev ☫ → To Debian-russian@lists.debian.org @ Thu, Aug 22, 2013 17:10 +0300
> On Thu, Aug 22, 2013 at 07:43:46PM +0600, Sergey Korobitsin wrote:
>
> Ну, if умеет отрицание:
>
> if ! echo "$TO_DISK_INFO" | fgrep -e "$SERIAL_SHORT" | fgrep -qe "$SERIALTO"; then
> ...
> fi
>
> В точности то, для чего создана the reserved word "!". Из dash(1):
>
> If the reserved word ! does not precede the pipeline, the exit status
> is the exit status of the last com‐ mand specified in the pipeline.
> Otherwise, the exit status is the logical NOT of the exit status of the
> last command. That is, if the last command returns zero, the exit
> status is 1; if the last command returns greater than zero, the exit
> status is zero.
>
> Или из bash(1):
>
> The return status of a pipeline is the exit status of the last
> command, unless the pipefail option is enabled. If pipefail is
> enabled, the pipeline's return status is the value of the last
> (rightmost) command to exit with a non-zero status, or zero if all
> commands exit successfully. If the reserved word ! precedes a
> pipeline, the exit status of that pipeline is the logical negation of
> the exit sta‐ tus as described above. The shell waits for all
> commands in the pipeline to terminate before returning a value.
>
> Так что if ! echo ... ; then ... сделает нужное.
Да, надо читать маны :-(. Я почему-то решил, что оно будет относиться к
первой команде в пайпе. А вообще, лучше perl взять, там unless есть :-).
--
Bright regards, Sergey Korobitsin,
Chief Research Officer
Arta Software, http://arta.kz/
xmpp:undertaker@jabber.arta.kz
--
Если мысли сходятся - значит, они ограничены
-- Саша & Наташа, периодически
Reply to: