Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • Very nice, +1. I wonder if it is indeed faster. Could you add some timing tests comparing it to the approaches in my answer? I expect yours will be faster but would like to see. Commented Oct 15, 2014 at 19:14
  • @terdon - that depends on the shell. It is almost definitely faster than tr in any shell, but the difference is iffy in bash for the ${var//$c/$newc/} case. I expect even in that case it will be faster by some margin, but I don't usually worry about that because for this stuff I always use dash - which is faster by orders of magnitude in generally every respect. And so it is hard to compare. Commented Oct 15, 2014 at 19:19
  • @terdon - I tried. But - even in bash - doing time (IFS=\"\'`; set -- $var; printf %s "$*") and time (var=${var//\'`/\"/}) both result in 0.0000s results for all fields. Am I doing something wrong, do you think? There's supposed to be a backslash before the backquote up there but I dunno how to put a backquote in a comment code field. Commented Oct 15, 2014 at 19:58