From: Simon Ruderich Date: Tue, 8 Oct 2013 14:29:15 +0000 (+0200) Subject: lib.sh: Add sed_i() compatibility function. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=f2ae0a2fdd20981164c1a10b0be4c354234610b0;p=config%2Fdotfiles.git lib.sh: Add sed_i() compatibility function. --- diff --git a/lib.sh b/lib.sh index 204a8e9..7b76a7c 100644 --- a/lib.sh +++ b/lib.sh @@ -50,6 +50,21 @@ installed_path() { ) } +# Usage: sed_i ... +# +# Uses .tmp as temporary file. sed -i is not compatible due to different +# implementations. +sed_i() { + # Get last argument. + last= + for x; do + last="$x" + done + + sed "$@" >"$last".tmp + mv "$last".tmp "$last" +} + # Print the current OS. The following OS are supported at the moment: # - Debian (debian) # - Gentoo (gentoo)