I need to form a single variable from a for loop.
My script:
#! /bin/sh
if [ "$#" -le 1 ]; then
    echo "Illegal number of parameters"
    exit 1
else
    # Form domains variable
    DOMAINS=""
    for i in "${@:2}"; do
        DOMAINS+="$i,"
    done
    echo "${DOMAINS::-1}"
fi
When I execute it:
    sh script.sh command domain1 domain2
I get the following error:
    certbot.sh: line 10: DOMAINS+=mmand,: not found
    certbot.sh: line 10: DOMAINS+=domain1.com,: not found
    certbot.sh: line 10: DOMAINS+=domain2.com,: not found
It seems as I used bash syntax since the following execution works:
    bash script.sh command domain1.com domain2.com
I get:
domain1.com,domain2.com
I need it to work as sh not bash. I can't seem to find a solution.
 
     
     
    