[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: |
Greg Wooledge |
Subject: |
Re: Problem outputting a quote in a variable expansion which is in a here doc |
Date: |
Wed, 7 Dec 2016 08:44:19 -0500 |
User-agent: |
Mutt/1.4.2.3i |
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.