[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Multiline variables?
From: |
Dan Kegel |
Subject: |
Re: Multiline variables? |
Date: |
Mon, 21 Sep 2020 08:00:13 -0700 |
Hrm. Setting SHELL to bash didn't seem to help here, neither on mac nor on
ubuntu 20.04.
The problem is restricted to make variables; letting the shell expand the
environment variable works.
Fun fact: bsd make successfully outputs multiline values, so I filed
https://savannah.gnu.org/bugs/index.php?59154
Here's a test case exploring the behavior with several ways of referencing
the variable, run with both gnu and bsd make.
$ expand < Makefile
all: xyz2 xyz3 xyz4
xyz2:
bash -c 'echo XYZ2: "${LONG}"'
xyz3:
echo 'XYZ3: $(LONG)'
xyz4:
echo "XYZ4: $$LONG"
$ cat bug.sh
#!/bin/sh
export LONG="multi
line"
echo "XYZ1: ${LONG}"
$1 -k
apt-cache policy $1 | grep Installed
dank@thinky:~/multiline$ sh bug.sh make
XYZ1: multi
line
bash -c 'echo XYZ2: "multi
/bin/sh: 1: Syntax error: Unterminated quoted string
make: *** [Makefile:4: xyz2] Error 2
echo 'XYZ3: multi
/bin/sh: 1: Syntax error: Unterminated quoted string
make: *** [Makefile:7: xyz3] Error 2
echo "XYZ4: $LONG"
XYZ4: multi
line
make: Target 'all' not remade because of errors.
Installed: 4.2.1-1.2
$ sh bug.sh bmake
XYZ1: multi
line
bash -c 'echo XYZ2: "multi
line"'
XYZ2: multi
line
echo 'XYZ3: multi
line'
XYZ3: multi
line
echo "XYZ4: $LONG"
XYZ4: multi
line
Installed: 20181221-2
On Sun, Sep 20, 2020 at 7:05 PM Zaar Hai <haizaar@gmail.com> wrote:
> Hi Dan,
>
> To add on your post, to work with env var containing multiline values I
> had to resort to bash. For quick test you can try:
>
> $ cat Makefile
> all:
> bash -c 'echo ${PUB}'
>
> or just set 'SHELL = /bin/bash' somewhere early in your Makefile
>
> Hope this helps,
> Zaar
>
> On Mon, 21 Sep 2020 at 04:22, Dan Kegel <dank@kegel.com> wrote:
>
>> Ha! The difference is the command base64 defaults to no wrapping on Mac
>> OS,
>> but wrapping on Linux.
>>
>> Mystery solved! I was looking under the wrong rock :-)
>> - Dan
>>
>> On Sun, Sep 20, 2020 at 1:40 AM Greg Chicares <gchicares@sbcglobal.net>
>> wrote:
>>
>> > On 2020-09-19 21:47, Dan Kegel wrote:
>> > >
>> > > export PUB="$(base64 < ~/.ssh/id_rsa.pub)"
>> > > make
>> > >
>> > > where Makefile is
>> > >
>> > > all:
>> > > echo "${PUB}"
>> > >
>> > > and it worked fine on Mac, despite PUB being a multiline string.
>> > >
>> > > On Ubuntu (even with the same version of gnu make),
>> > > it breaks terribly, complaining about a missing quote
>> > > on the end of the first line of the string. Evidently this is not
>> > portable.
>> > [...]
>> > > I couldn't tell why they worked on the mac. Any guesses?
>> >
>> > Just a guess--If $PUB is exported before running make, in an
>> > interactive shell, then is that shell zsh by default for mac,
>> > but bash for ubuntu?
>> >
>> >
>> >
>>
>
>
> --
> Zaar
>