bug-bash
[Top][All Lists]
Advanced

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

Re: Problem outputting a quote in a variable expansion which is in a her


From: Daniel Einspanjer
Subject: Re: Problem outputting a quote in a variable expansion which is in a here doc
Date: Wed, 07 Dec 2016 14:03:11 +0000

Awesome, thanks for this tip!

On Wed, Dec 7, 2016 at 8:44 AM Greg Wooledge <address@hidden> wrote:
On Wed, Dec 07, 2016 at 12:56:00AM +0000, Daniel Einspanjer wrote:
> echo The desired output is:
> echo "var = \"test test\""

imadev:~$ q=\"
imadev:~$ var="a variable"
imadev:~$ cat <<EOF
> ${var:+var = $q$var$q}
> EOF
var = "a variable"
imadev:~$ echo "$BASH_VERSION"
4.4.0(1)-release

Putting literal quotes (to be echoed) inside variables helps work around
a fairly large number of tricky situations like this.  It's a useful
general-purpose hack to keep in the back of your mind for the future.

reply via email to

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