ryanmjacobs/c

GNU/BSD sed compatibility

ryanmjacobs opened this issue · 6 comments

We need a command that doesn't require gnu-sed to be installed with brew.

This should work on both GNU and BSD systems:

$ cat > file.c
#!/usr/bin/c blah blah blah
^D
$ sed -i.bak '1!b;s/^#!/\/\/#!/' file.c
$ cat file.c
//#!/usr/bin/c blah blah blah

However, I don't have access to a BSD system...
It works just fine on GNU. Can someone confirm that it works on BSD systems, too? Thanks.

That fails for me on FreeBSD:

alistair@loki:~$ cat > file.c
#!/usr/bin/c blah blah blah
alistair@loki:~$ sed -i.bak '1!b;s/^#!/\/\/#!/' file.c
sed: 1: "1!b;s/^#!/\/\/#!/": undefined label ';s/^#!/\/\/#!/'

Since only the first line is considered, this works (also tested on FreeBSD).

$ cat file.c
#!/usr/bin/c blah blah blah
$ sed -i.bak '1,1s/^#!/\/\/#!/' file.c
$ cat file.c
//#!/usr/bin/c blah blah blah
$ 

Yep, that works for me!
(also tested on OSX Mavericks.)

@lukaf Cool that works for GNU, too! I'll use that later today. Then, we should be able to get a homebrew package going.

Okay, I've merged in this change. Can someone try using the new script?

I have removed sed completely by using tail instead. We shouldn't have these compatibility issues any more.