Date:        Tue, 16 May 2017 17:29:13 +0100
    From:        Stephane Chazelas <stephane.chaze...@gmail.com>
    Message-ID:  <20170516162913.gd3...@chaz.gmail.com>

  | Sorry about that. I hadn't seen that message at the time I
  | replied.

No, no problem, it was my fault - I should have not gotten those issues
incorrect in the initial message, and had to add corrections later...

  | Depends. If quoting only a handful a arguments, then that call
  | to awk might cost you you a couple of milliseconds indeed. But
  | if processing thousands, you might find that it saves a few
  | seconds.

And if I really had an application, whose only purpose was to quote
huge numbers of strings, and do nothing else, then I'd write it in a
proper compiled language, and it would be even faster.   But I don't.

The point is that applications for that kind of thing are very rare - on
the other hand a script that needs to save the value of a variable, so it
can be restored later, is not rare at all - if it is a one off you just
assign to a temporary, and restore it, and all is fine.

But if you have an application which needs to effectively stack the saved
values, and pop them later, then (unless you can count upon the shell
implementing some form of array, which you can use to implement the stack,
which you cannot in a posix shell) we need to do string manipulation, and
for that we need to make sure that the variable value gets properly quoted,

That is what (from Steffen's original message) I assumed was wanted here.

  | My quote() works like your quote() when passed a single
  | argument, mine can take more than one and still produce a
  | useful outcome (and helps with performance).

Only if you actually anticipate it being called with multiple
arguments, otherwise there's extra overhead in that loop.   Either
way, the single/multiple arg question is orthogonal to the real question
here, either version could be made to handle multiple args, or just one,
depending upon the application requirements.

kre


Reply via email to