Skip to content
This repository has been archived by the owner on Apr 25, 2021. It is now read-only.

sed statement misbehaves with BSD based sed #186

Closed
timcharper opened this issue Sep 26, 2017 · 0 comments
Closed

sed statement misbehaves with BSD based sed #186

timcharper opened this issue Sep 26, 2017 · 0 comments

Comments

@timcharper
Copy link
Contributor

timcharper commented Sep 26, 2017

The logic on the following line only works with GNU sed variants, but breaks horribly on Darwin variants.

cat "$1" | sed '/^\#/d;s/\r$//' | while read -r line || [[ -n "$line" ]]; do

Observe:

OS X (BSD sed)

$ echo "-J-server" | sed 's/\r$//'
-J-serve

Linux (GNU sed)

echo "-J-server" | sed 's/\r$//'
-J-server

BSD removes the last r from all lines that end in the letter r.

Different approach

We can use pass the literal "\r" character to sed. This seems to work:

OS X (BSD sed)

$ echo "-J-server" | sed $'s/\r$//'
-J-server

$ printf $'ABCD\r\nABCD\n' | sed $'s/\r$//' | xxd
0000000: 4142 4344 0a41 4243 440a                 ABCD.ABCD.

Linux (GNU sed)

$ echo "-J-server" | sed $'s/\r$//'
-J-server

$ printf $'ABCD\r\nABCD\n' | sed $'s/\r$//' | xxd
0000000: 4142 4344 0a41 4243 440a                 ABCD.ABCD.
timcharper added a commit to timcharper/sbt-launcher-package that referenced this issue Sep 26, 2017
BSD sed interprets sed 's/\r//' as "replace the literal letter r". A more compatible approach delegates the interpretation of this sequence to bash.

Fixes sbt#186
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant