[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ${p+\"$p\"}
From: |
Greg Wooledge |
Subject: |
Re: ${p+\"$p\"} |
Date: |
Mon, 21 Jan 2019 09:05:26 -0500 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Mon, Jan 21, 2019 at 09:14:26PM +0800, Dan Jacobson wrote:
> So how am I to get
> "A"
> with bash?
>
> $ cat z
> p=A
> cat <<EOF
> ${p+\"$p\"}
> ${p+"$p"}
> EOF
> $ bash z
> \"A\"
> A
> $ dash z
> "A" <=========WANT THIS
> A
> $ bash --version
> GNU bash, version 5.0.0(1)-release...
So, if I'm reading this correctly, you have a variable p whose content
is a string ABC (without quotes). You want a parameter expansion which
checks whether the variable p is set, and if so, emits the string "ABC"
(with quotes).
Here you go:
p=ABC
q=\"
printf '%s\n' "${p+$q$p$q}"