[PATCH 3/4] email-sh-functions: make 'merge_addresses' more flexible

Artem Bityutskiy dedekind1 at gmail.com
Mon Feb 10 01:18:58 PST 2014

From: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>

Jacob made 'merge_addresses()' to be able to merge multi-line input. And this
basically makes the second argument of the function optional. Indeed, now one
can call 'merge_addresses()' with a single argument like:


and the function would merge this. And this is actally how Jacob is going to
use this in his next patch.

So let's just do this - make the second argument optional.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
 email/aiaiai-email-sh-functions | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/email/aiaiai-email-sh-functions b/email/aiaiai-email-sh-functions
index b36a4a7..aceeade 100644
--- a/email/aiaiai-email-sh-functions
+++ b/email/aiaiai-email-sh-functions
@@ -103,19 +103,22 @@ fetch_project_name()
 	printf "%s" "$list" | LC_ALL=C sed -n -e "s/.*$l+\([^@]\+\)@$d.*/\1/p" | head -n1
-# Merge e-mail addresses into a comma-separated list
+# Merge e-mail addresses into a comma-separated list. This function may have
+# one or two input arguments. Each input argument is expected to contain
+# multiple lines of comma-separated e-mail addresses. This function will merge
+# them all into one single comma-separated line and print it.
 # Usage: merge_addresses "addr1" "addr2"
 	local addr1="$1"; shift
-	local addr2="$1"; shift
+	local addr2="${1:-}"
 	local list
 	# We assume that the input arguments may have multiple lines
 	list="$(printf "%s" "${addr1}${__br}${addr2}" | LC_ALL=C tr "\n" ",")"
-	printf "%s" "$list" | LC_ALL=C sed -e "s/,,/,/g" -e "s/^,//" \
-		                           -e "s/,$//" -e "s/[[:blank:]]\+/ /g"
+	printf "%s" "$list" | LC_ALL=C sed -e "s/,\+/,/g" -e "s/^,\+//" \
+		                           -e "s/,\+$//" -e "s/[[:blank:]]\+/ /g"
 # A helper function for 'ini_config_get()' (from libshell) which fails when

More information about the aiaiai mailing list