bug-bash
[Top][All Lists]
Advanced

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

Re: ${p+\"$p\"}


From: don fong
Subject: Re: ${p+\"$p\"}
Date: Mon, 21 Jan 2019 13:29:34 -0800

here is another possible workaround, apologies if this has already been
mentioned.

cat <<EOF
${p+*$(echo \"$p\")*}
${p+"$p"}
EOF


On Mon, Jan 21, 2019 at 6:07 AM Greg Wooledge <address@hidden> wrote:

> 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}"
>
>


reply via email to

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