Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=gnometesting.git;a=commitdiff;h=8a9122975f01aa254a6d63b0979ab3d25f3816db
commit 8a9122975f01aa254a6d63b0979ab3d25f3816db Author: Michel Hermier <herm...@frugalware.org> Date: Tue Mar 23 11:46:57 2010 +0100 util.sh * Introduce Freplace function. * Factorise Fsed and Freplace in private __Fsed. diff --git a/source/include/util.sh b/source/include/util.sh index 1606de4..fba4b37 100644 --- a/source/include/util.sh +++ b/source/include/util.sh @@ -494,15 +494,45 @@ Fln() { } ### +# * __Fsed(): Private implementation of Fsed and Freplace. Parameters: +# 1) regexp (see man sed!) 2) replacement 3) file to edit in place. +### +__Fsed() { + if [ ! -e $i ]; then + error "File $i not found." + Fdie + fi + if [ ! -f $i ]; then + error "File $i is not a regular file." + Fdie + fi + sed -i -e "s|$1|$2|g" "$3" || Fdie +} + +### # * Fsed(): Use sed on file(s). Parameters: 1) regexp (see man sed!) 2) # replacement 3) file(s) to edit in place. ### Fsed() { local i Fcd - for i in ${@:3:$#}; do + for i in "${@:3:$#}"; do Fmessage "Using sed with file: $i" - sed -i -e "s|$1|$2|g" "$i" || Fdie + __Fsed "$1" "$2" "$i" + done +} + +### +# * Freplace(): Do some parameter substitution on file(s). The parameters +# should be escaped using the "@parameter@" syntax. Parameters: +# 1) Variable to substituate 2) file(s) where the substitution happens. +### +Freplace() { + local i + Fcd + for i in "${@:2:$#}"; do + Fmessage "Subtituing $1 in file: $i" + eval "__Fsed '@$1@' \"\${$1}\" \"\$i\"" done } _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git