Date: Tue, 16 May 2017 10:03:56 +0700 From: Robert Elz <k...@munnari.oz.au> Message-ID: <14296.1494903...@andromeda.noi.kre.to>
I keep replying to my own mail. This is really not a good sign! | Alternatively, you could implement this as an external #! script, that | would be a lot slower, but would at least avoid that issue. And of course, you could also write it as a sub-shell function - as this func has no intended effects on the calling shell, so doing it that way avoids problems of namespace pollution, or any requirement that IFS or the options be restored. To do that, instead of quote() { # code... } write quote() ( # code, but not bothering with any save/restore and using any var names ) This will usually be slower than the "normal" function, but not nearly as slow as an external #! script (particularly as it only needs to be "compiled" once, rather than every time it is run, which an external script would require.) Also, to be 100% correct, in the {} version, the code that saves/restores IFS should be checking if IFS was set or not when it is being saved, and unsetting, rather than setting it to a null string, when restoring its value if it had been unset perviously. Fixing that is left as an exercise... (hint: the answer does not require using any more variables). kre