[Top][All Lists]

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

Re: here strings fold newlines on MacOS

Subject: Re: here strings fold newlines on MacOS
Date: Sun, 31 Jan 2021 02:28:39 +0000
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.7.0

On 30/01/2021 22:44, Rich Lafferty wrote:
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: darwin18.7.0
Compiler: clang
uname output: Darwin flounder.home.mati.ca 18.7.0 Darwin Kernel Version 18.7.0: 
Tue Nov 10 00:07:31 PST 2020; root:xnu-4903.278.51~1/RELEASE_X86_64 x86_64
Machine Type: x86_64-apple-darwin18.7.0

Bash Version: 5.1
Patch Level: 0
Release Status: release

Here strings ('<<<') fold newlines into spaces on MacOS, but not on Linux,
leading to incompatibilites in bash code expected to work the same on both


On Linux:

$ od -bc <<< $(echo -e "foo\nbar")
0000000 146 157 157 012 142 141 162 012
  f o o \n b a r \n

On MacOS:

$ od -bc <<< $(echo -e "foo\nbar")
0000000 146 157 157 040 142 141 162 012
  f o o b a r \n

Are you certain that you're not testing /bin/bash (version 3.2.57) in the case of macOS? I ask because the bug you describe is said to have been addressed by the release of 4.4-beta [1].

z.  Bash no longer splits the expansion of here-strings, as the
    documentation has always said.

You can work around it by double quoting the command substitution.

[1] https://tiswww.case.edu/php/chet/bash/CHANGES

Kerin Millar

reply via email to

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