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

Re: The big kre zsh bug report



(For some reason gmail put your reply in spam, I only found it by accident.)

On Fri, Dec 21, 2018 at 3:31 AM Robert Elz <kre@xxxxxxxxxxxxx> wrote:
>
>   | It seems to me that changing this for $=t in zsh native mode might
>   | break a lot of things, so I'll leave it open for discussion as to
>   | whether it's feasible to change it only for emulation mode.  However,
>   | it does differ from the most recent version of bash I have handy.

By this I meant zsh's current behavior differs from bash, so we ought
to at least consider changing it in emulation.

> From the version in the prompt string where you illustrated bash
> behaviour later, you seem to be testing against a very old bash

It's what's on CentOS 6.10.

> (though apparently bash 3 still exists in the wild).

MacOS 10.13 appears to have bash3, at least based on the prompt.

>   | For the lazy or very busy reader:
>   |
>   | -h  Locate and remember utilities invoked by functions as those
>   | functions are defined (the utilities are normally located when the
>   | function is executed).
>
> Yes, I know what it means.

Obviously you do, but I didn't until it was mentioned here, so I
assume the rest of the zsh-workers audience might not either.

>  I cannot think of a use for it, nor have
> I ever seen any script that would ever use it, nor does anything I
> know of implement it

It doesn't even seem possible to implement sanely, unless perhaps by
freezing $PATH and putting the shell in a virtual chroot jail.

var=grep
$var "$@"

would seem to be enough to thwart it without some really elaborate
"compile time" analysis of what $var was going to yeild.

>   | var='"z"'; case ${var} in (${var}) printf M;; (*) printf X;; esac
>   |
>   | This also prints M.  If backslash-z should become a quoted z,
>   | shouldn't the above case also become a quoted z?
>
> No.   It all comes from the use of RE's to define how glob works
> (and the ancient implementation) - '\' quotes magic in an RE, other
> forms of shell quoting do not.

OK, that's understandable.  Any situation in which given (just for
example) var='[a-z]' we interpret $var as a character class, we ought
to also when given var='\z' treat $var as a literal z.

As mentioned above about $=t for splitting, I'm not sure we can safely
apply this to $~var without changing some expected behavior, so it'll
require careful consideration.

> In native zsh mode if you want to change that to be more like csh,
> which did complain about invalid patterns, that's fine, but for emulating
> sh it really isn't.

None of the discussion of $var interpolation of '\z' in pattern
context has any relationship to the discussion about treatment of bad
patterns.

>   | There isn't any --emulate bash, really, it's merly a synonym for
>   | --emulate sh.
>
> In that case, I would suggest deleting it.   It gives a false impression.
> bash has lots of stuff that sh does not have, how close some of that
> is to zsh native mode I have no idea.
>
>   | And therefore no, it's not intended to be perfect.
>
> It depends what you're aiming for with --emulate ... if it is just so you
> can run native sh scripts, then most of this does not matter.

It's just so you can run native sh scripts.  It's not intended to turn
zsh into a portability test platform.  Really it's so that you can do

ln -s /bin/zsh bash

The --emulation option is just a way to talk zsh into behaving as if
$0 were changed.  --emulate csh is even farther from accurate.

>   | Checking for overflow here seems like a lot of computational expense for a
>   | case that probably only happens in test suites.  Since zsh implements arrays
>   | as actual non-sparse C arrays, memory is going to explode long before
>   | anything manages to assign that many positional parameters.
>
> Don't bet on it.   An array with 2^32 unset elements, followed by one set
> (assuming it is implemented in a rational way) is just 8 * (2^32 + 1) bytes,

I don't recall exactly but it's probably more like double that (2^32
pointers to things representing unset elements, not 2^32 null
pointers).

Nevertheless, point taken.



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