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*

5
  • printf %q is initially from ksh93 and is also supported by zsh's printf, but each implementation outputs quoting in the syntax of the respective shell and is generally unsafe to use in a different locale from the one it was generated in and may not be safe if not interpreted by the shell it was intended for. Calling printf %q in the C locale with most implementations is more likely to produce an output that works reliably in all the shells that support ksh93's $'...' form of quote (a subset of which is now specified by POSIX). Commented Oct 9 at 19:18
  • If the values selected by awk contain space (assuming default IFS) or ?*[] (and maybe more) they are split and/or globbed before they are passed to printf and thus %q has no chance to quote them, except in 'plain' zsh. Commented Oct 10 at 0:49
  • that's true. i should have used an array instead. Commented Oct 10 at 0:59
  • here, when you have the values in shell variables, you could also directly run the final program, bypassing the quoting issues srvctl add database -d "${a[0]}" -o "${a[1]}". (Of course this won't work if they were going to e.g. send the command off to another host to run, but the Q doesn't seem exactly clear on that.) Commented Oct 10 at 6:12
  • could do that. or just pipe it into sh or bash. there's thousands of possibilities. Commented Oct 10 at 6:15