I'm writing shell scripts for my server, which is a shared hosting running FreeBSD. I also want to be able to test them locally, on my PC running Linux. Hence, I'm trying to write them in a portable way, but with sed
I see no way to do that.
Part of my website uses generated static HTML files, and this sed line inserts correct DOCTYPE after each regeneration:
sed -i '1s/^/<!DOCTYPE html> \n/' ${file_name.html}
It works with GNU sed
on Linux, but FreeBSD sed
expects the first argument after -i
option to be extension for backup copy. This is how it would look like:
sed -i '' '1s/^/<!DOCTYPE html> \n/' ${file_name.html}
However, GNU sed
in turn expects the expression to follow immediately after -i
.
(It also requires fixes with newline handling, but that's already answered in here)
Of course I can include this change in my server copy of the script, but that would mess i.e. my use of VCS for versioning. Is there a way to achieve this with sed in a fully portable way?
-i
– iruvar Sep 29 '13 at 23:34