bug-bash
[Top][All Lists]
Advanced

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

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


From: Bize Ma
Subject: Re: ${p+\"$p\"}
Date: Mon, 21 Jan 2019 17:51:46 -0400

------------------------------
*From*: Robert Elz
*Subject*: Re: ${p+\"$p\"}
*Date*: Mon, 21 Jan 2019 23:38:22 +0700
------------------------------

(...)
> With the quotes, most other shells produce the output reported
> from dash (that includes ksh93, yash, ...)   zsh just says it iis
> a parse error, which is probably a rational choice!

> Nothing else I tested produces what bash does, which does seem
> to be a kind of odd pair of results.

That is quite inexact, there are four groups:

heirloom sh    : "A" \"A\" \\"A\\" \\\"A\\\"

ash            : A \"A\" \A\ \\"A\\"
dash           : A \"A\" \A\ \\"A\\"
b43sh          : A \"A\" \A\ \\"A\\"
b44sh          : A \"A\" \A\ \\"A\\"
posixbash      : A \"A\" \A\ \\"A\\"

yash           : A "A" \A\ \"A\"
y2sh           : A "A" \A\ \"A\"
posh           : A "A" \A\ \"A\"
lksh           : A "A" \A\ \"A\"
mksh           : A "A" \A\ \"A\"
ksh93          : A "A" \A\ \"A\"
attsh          : A "A" \A\ \"A\"

zsh/sh         : ./t.sh:7: parse error
zsh/ksh        : ./t.sh:7: parse error
zsh            : ./t.sh:7: parse error


But yes:


> But this is an area that is a monumental mess, and the only rational
> choice is to find some workaround which does not involve putting
> a " inside a var expansion inside a here doc.

Maybe:

    p=A
    q='"'
    cat <<_EOF_
    ${p+$q$p$q} ${p+\\$q$p\\$q}
    _EOF_

Which yields "A" \"A\"  in all shells tested (except heirloom bourne shell).

Or, even simpler (depending on use):

    echo ${p+"$p"} ${p+\"$p\"} ${p+\\"$p\\"} ${p+\\\"$p\\\"}


reply via email to

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