[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
- [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Peng Yu, 2015/03/24
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Eduardo A . Bustamante López, 2015/03/24
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Eric Blake, 2015/03/25
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Eric Blake, 2015/03/25
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Chet Ramey, 2015/03/26
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Eric Blake, 2015/03/26
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?,
Stephane Chazelas <=
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Greg Wooledge, 2015/03/30
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Stephane Chazelas, 2015/03/30
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Greg Wooledge, 2015/03/30
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Stephane Chazelas, 2015/03/30
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Greg Wooledge, 2015/03/30
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Stephane Chazelas, 2015/03/30
- Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Stephane Chazelas, 2015/03/29
Re: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?, Stephane Chazelas, 2015/03/25