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

Re: expr length "$val" returns the wrong length for values containing NULL (\\0)



10.12.2015, 12:38, "Peter Stephenson" <p.stephenson@xxxxxxxxxxx>:
> On Thu, 10 Dec 2015 15:30:03 +1030
> D Gowers <finticemo@xxxxxxxxx> wrote:
>>  I am aware of the prevalence of NUL-terminated strings, since I've coded in
>>  C in the past, that's why I wrote 'considerable bother to fix it'.
>>  Nevertheless, for a purpose such as argument passing, size + data is
>>  clearly better (easier to secure and more flexible)
>
> The main point here --- which doesn't seem to have been mentioned --- is
> that expr isn't a shell builtin. Within the shell, we do indeed treat

It was not directly mentioned, but I did say that you need to write `expr` as a zsh function for this code to work as expected.

> NUL characters as normal chracters. As soon as you pass them outside,
> you are stuck --- there's no mechanism nor even convention for passing

There actually is: use file descriptors in one way (pipes) or the other (temporary files, fd will be created by the program). This is most universal, and many programs work with data with NULs (e.g. `grep --null` with `xargs -0`). Still not everything supports this variant though. Most other variants I know include escaping/quoting of some sort and are much more ad-hoc.

> embedded NULLs which would require a rethink about the standard
> library conventions. This is a problem, but not a shell problem.
> So if you want to continue the argument, you'll need to find some
> higher power mailing list.
>
> pws



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