]> ruderich.org/simon Gitweb - config/dotfiles.git/commitdiff
lib.sh: Add sed_i() compatibility function.
authorSimon Ruderich <simon@ruderich.org>
Tue, 8 Oct 2013 14:29:15 +0000 (16:29 +0200)
committerSimon Ruderich <simon@ruderich.org>
Tue, 8 Oct 2013 14:29:15 +0000 (16:29 +0200)
lib.sh

diff --git a/lib.sh b/lib.sh
index 204a8e9f95a2e695c4822682f85de7bf6cb1727c..7b76a7cab66b08cad1d639f0c059fae2dc637798 100644 (file)
--- a/lib.sh
+++ b/lib.sh
@@ -50,6 +50,21 @@ installed_path() {
     )
 }
 
+# Usage: sed_i ... <file>
+#
+# Uses <file>.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)