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