help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Transform strings with special characters so that the st


From: Stephane Chazelas
Subject: Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?
Date: Sun, 29 Mar 2015 10:41:53 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

2015-03-25 15:42:35 -0600, Eric Blake:
> On 03/25/2015 03:26 PM, Eric Blake wrote:
>
> >>> printf -v escaped_var %q "$var"
> >
> > Fork-free.
>
> But requires bash extensions ('printf -v var' and 'printf %q' are both
> bashisms not likely to work in other shells)
[...]

Strictly speaking, %q comes from ksh93 (can't tell if it was
there from the start or not though). Both zsh and bash when
they introduced their own printf builtin (2001 and 1998
respectively) had %q from the start.

ksh93 doesn't need a -v because it doesn't fork+pipe in
var=$(printf %s "$var") (and that output will never end in a
newline character).

zsh has variable expansion flags: ${(q)var}, ${(qq)var},
${(qqq)var}, ${(qqqq)var} for various forms of quoting.

-- 
Stephane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]