I'm trying to write up a little helper script that will change permissions and ownership to some sites on a server.Right now, I can either pass in 1 site, or do all via simply skipping that argument.What I am finding is that I need to be able to apply to multiple sites on the server, but not all, so I tried making an attempt at passing an array via:SLIST=(my.site.com your.site.com)./website-perms 644 755 kevin ${SLIST[@]}However, it only does the first item in the array my.site.comHow do I fix this so I can pass in an array of sites?FULL CODE#!/bin/bash# Done nightly, and copied to /usr/bin/if [[ $EUID -ne 0 ]]; then   echo This script must be run as root 1>&2   exit 1fiif [ $# -eq 0 ]; then    echo usage: ./website-perms.sh fileperm folderperm owner (1|2) (1=kevin,2=www-data) (optional) Site Array    exit 1fifunction chg_perms() {    echo find $1 -type f -exec chmod $2 {} \\;    echo find $1 -type d -exec chmod $3 {} \\;    find $1 -type f -exec chmod $2 {} \;    find $1 -type d -exec chmod $3 {} \;    echo -- chg_perms done;}function chg_owner() {    echo chown -R $2:www-data $1;    chown -R $2:www-data $1;    echo -- chg_owner done;}SITES=$4;if [ -z $SITES ]; then    for dir in /var/www/httpdocs/*/    do        dir=${dir%*/}        chg_perms /var/www/httpdocs/${dir##*/} $1 $2        chg_owner /var/www/httpdocs/${dir##*/} $3    done;else    for dir in ${SITES[@]} #ONLY DOES THE FIRST ITEM    do        chg_perms /var/www/httpdocs/$dir $1 $2        chg_owner /var/www/httpdocs/$dir $3    donefi;
Looping through a shell array given as parameter
bash;shell script;array
Nice script.  Usually I would use all remaining arguments as the list of sites.  Something like this (I have not tested these mods):if [ $# -lt 3 ]; then    echo >&2 usage: $0 fileperm folderperm owner [site ...]    exit 1fi[ . . . ]fileperm=$1folderperm=$2owner=$3shift 3             # shift first 3 args off of listif [ $# -eq 0 ]; then    for dir in /var/www/httpdocs/*/    #stackexchange syntax coloring fix*/    do        dir=${dir%/*}        chg_perms /var/www/httpdocs/${dir##*/} $fileperm $folderperm        chg_owner /var/www/httpdocs/${dir##*/} $owner    done;else    for dir           # step through positional args ($1,$2,...,$N)    do        chg_perms /var/www/httpdocs/$dir $fileperm $folderperm        chg_owner /var/www/httpdocs/$dir $owner    donefi