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

Re: grammar triviality with '&&'



On 03/01/2015 09:22 PM, Kurtis Rader wrote:

One obvious cost is that anyone reading a script that uses the feature will naturally assume the author made a mistake and the script is invalid.

So don't use it if, when or where tradition trumps practicality--which is almost everywhere.
The reason this restriction exists is not arbitrary.

That may very well be the case, which is why I raised the question, but it seems that it might not be the case after all (Lawrence). I'm over fascinated by this sort of minutia.
It is a an obvious and natural consequence of how the grammar was interpreted by the person(s) who wrote the code for the Bourne-shell, Bash, Zsh, etcetera. Why is it simpler for the code to "just grab the errorlevel of the previous command" when it sees a leading "&&" or "||"?

But is that not what it already does? The question is whether a line break or a semi *necessarily* prevents that. IOW, what ambiguity would this cause:

[ -e file1 ]
&& [ -e file2 ]
Also, it is not just a matter of changing the zsh implementation. Unit tests need to be added and existing tests likely updated. Documentation needs to be changed. Whether the change might break existing uses has to be carefully considered.

Absolutely, and that is probably reason enough why it won't happen. It would have to be nothing more than a relaxation of an arbitrary rule ( **if** it is arbitrary)--maybe there is a very good reason why errorlevel can't be passed beyond a newline or semi. If there is such a good reason, I'd be educated to learn what it is. But since "[[ $? -eq 0 ]]" works past the newline, at this point I can't see what the linewrap would *necessarily* break.

You say "I'd use it for sure". Please provide a non-contrived example, preferably two or three, where this would be useful.

if [ -e 'shelly.txt' ]
&& [ -n "$ozymandias" ]
&& [ grep "I met a traveler" ]
then
  echo "Look on my works, ye mighty"
fi


... I have a trivial preference for that form, I find it neater. It is very unimportant.

How hard is it to be explicit and include the "[[ $? -eq 0 ]]" in a script? If this feature were truly useful for interactive use I might agree with you. But I see no evidence and my 30+ years experience that it has no use outside of making a tiny percentage of scripts a few characters shorter.

Exactly so. Whereas I'd like it for saving me the line continuation backslash, that is monumentally trivial, I'm interested in the theory of the thing. I like Lawrence's thinking on the matter, however.

Don't take this more seriously than I take it.



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