Le 22 juil. 2012 à 09:58, Stefano Lattarini a écrit :
>> I personally use it extensively in my test suites, as I find this
>> much more legible:
>>
>> ! list_logs | grep .
>>
> Ah, but this doesn't do what you expect:
>
> $ bash -c '! echo x | grep .'; echo st = $?
> x
> st = 0
> $ bash -c '! echo | grep .'; echo st = $?
> st = 1
>
> To "deny" the pipeline, you need to enclose it in "()" or "{}":
>
> $ bash -c '! (echo x | grep .)'; echo st = $?
> x
> st = 1
> $ bash -c '! (echo | grep .)'; echo st = $?
> st = 0
>
> Which proves that my preferred idiom was actually clear :-)
Actually, you should display the exit status of the command, not
that of the shell. And really, that's brand new to me, and my
bash 3.2 does not seem to agree.
bash -c '! echo x | grep .'; echo st = $?
x
st = 1
The ! is about the exit status of the whole pipe. The doc reads:
A `pipeline' is a sequence of simple commands separated by `|'.
The format for a pipeline is
[`time' [`-p']] [`!'] COMMAND1 [`|' COMMAND2 …]
If the reserved word ! precedes a pipeline, the exit status of that
pipeline is the logical negation of the exit status as described above.
http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
states the same. I don't understand how you have your first result.