From 3de8ea1b230987c3125df5d8d181e295d5d1947f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 29 Apr 2024 23:07:52 +0200 Subject: [PATCH] cd_sed --- cd.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cd.sh b/cd.sh index 9af56b4..60e36e1 100644 --- a/cd.sh +++ b/cd.sh @@ -126,12 +126,7 @@ deb https://deb.debian.org/debian-security bookworm-security main ;; "alma") file="/etc/yum.repos.d/almalinux.repo" - for expression in \ - "|^m|# m|" \ - "|^# b|b|" \ - ; do - sed --in-place "s${expression}g" "${file}" || exit - done + cd_sed "${file}" "|^m|# m|" "|^# b|b|" cd_cat "${file}" ;; *) cd_error_os "cd_set_packages_repositories" ;; @@ -337,6 +332,18 @@ cd_rm () { fi } +cd_sed () { +local expression +local file + if [ -f "${1}" ] ; then + file="${1}" + shift + for expression in "${@}" ; do + sed --in-place "s${expression}g" "${file}" || exit + done + fi +} + cd_step () { if [ "${1}" ] ; then CD_STEP=$((CD_STEP+1))