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

Re: unintuitive bracketing with return value



On 10/18/22 10:47, Ray Andrews wrote:
I vaguely remember mentioning this before but I don't recall what the understanding should be:

[ "${${1}##*[*?]*}" ] && {
echo "no wildcards"; printenv "$1" } || echo wildcards present

... I'm obviously testing for the presence of wildcards before sending "$1" to 'printenv', unfortunately the '||' responds to the return value of 'printenv' and not, as I intend, for the '||' to respond to the first test (presence of wildcards).  If it
was not bracketed there would be no issue of course, but shouldn't the brackets do the intuitive thing and force the final '||' to be the alternative to the first '&&'?  It's easy to just write the thing as an 'if/else' statement and avoid the issue, but
still the above seems very counter intuitive.  ... Tho of course one could get used to it and prefer it that way but still it seems weird.




https://mywiki.wooledge.org/BashPitfalls#pf22




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