From 7b1e34f6259353a121dce485c56ffe635f84262d Mon Sep 17 00:00:00 2001 From: Lucas Date: Wed, 20 Apr 2022 12:47:40 +0000 Subject: [PATCH] Refactor: join strings in shell instead of relying on paste --- cassh.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cassh.sh b/cassh.sh index d297165..1b19f91 100644 --- a/cassh.sh +++ b/cassh.sh @@ -92,6 +92,19 @@ format() echo "$_out" } +strjoin() +{ + _c=$1 + shift + + _out= + for _s; do + _out=${_out:+$_out$_c}$_s + done + + echo "$_out" +} + main_issue() { hflag= @@ -175,13 +188,11 @@ main_mkfile() case $file in authorized_keys) - options=$(printf "%s\n" cert-authority "$@" | paste -sd , -) - printf "%s " "$options" + printf "%s " "$(strjoin , cert-authority "$@")" ;; known_hosts) - hostnames=$(printf "%s\n" "$@" | paste -sd , -) - if [ -n "$hostnames" ]; then - printf "@cert-authority %s " "$hostnames" + if [ $# -gt 0 ]; then + printf "@cert-authority %s " "$(strjoin , "$@")" else printf "@cert-authority " fi