diff --git a/setup.sh b/setup.sh index 8fb61fe..1d9fc4e 100644 --- a/setup.sh +++ b/setup.sh @@ -526,6 +526,23 @@ function in_file_in_array_remove_n () { arg_file="${1:?}" arg_array="${2:?}" arg_string="${3:?}" + + # Look for any line that contains "${arg_string}", delete that string + # + # For following example text we're assuming that: + # - "${arg_array}" equals 'HOOKS' + # - "${arg_string}" equals 'fsck' + # + # First -e expression removes 'fsck' wherever it is defined as the one + # and only element of any HOOKS=(fsck) should such a line exist. + # + # Second -e expression finds string 'fsck' where it's preceded by space + # character(s) and followed by either space character(s) or a closing + # parenthesis. + # + # Third -e expression finds string 'fsck' where it's preceded by space + # character(s) or an opening parenthesis and followed space + # character(s). sed -ri \ -e 's'$'\x1''((\()('"${arg_string}"')(\)))'$'\x1''\2\4'$'\x1''g' \ -e 's'$'\x1''('"${arg_array}"'=.*?)([[:space:]]+'"${arg_string}"')([[:space:]]+|\))'$'\x1''\1\3'$'\x1''g' \