From 8348ecd5e6759f9551fac0431a45c3bdffc36956 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 22 Oct 2013 21:15:31 +0200 Subject: [PATCH] lib.sh: Generalize sed_i() to cmd_i() for in-place changes. --- lib.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib.sh b/lib.sh index 7b76a7c..5abd278 100644 --- a/lib.sh +++ b/lib.sh @@ -50,21 +50,29 @@ installed_path() { ) } -# Usage: sed_i ... +# Usage: cmd_i ... # -# Uses .tmp as temporary file. sed -i is not compatible due to different -# implementations. -sed_i() { +# Run with all arguments (including the last file) and write the result +# to the temporary file .tmp and then renamed that file to . This +# can't be done in-place (e.g. cmd file) because it truncates the file. +cmd_i() { # Get last argument. last= for x; do last="$x" done - sed "$@" >"$last".tmp + "$@" >"$last".tmp mv "$last".tmp "$last" } +# Usage: sed_i ... +# +# sed -i is not compatible due to different implementations. See cmd_i. +sed_i() { + cmd_i sed "$@" +} + # Print the current OS. The following OS are supported at the moment: # - Debian (debian) # - Gentoo (gentoo) -- 2.43.2