|
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 |
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.
[Prev in Thread] | Current Thread | [Next in Thread] |