I have a while loop in a for loop to create user accounts in drupal using drush and it's not iterating through the sequence properly. It creates the accounts or all the domains fine, but the while loop does not create the user roles after the first account. Anyone see my mistake?
#add the user
USERLIST=(
"$USER,page_creator"
#"$USER,layout_manager"
"$USER,page_reviewer"
"$USER,landing_page_creator"
"$USER,landing_page_reviewer"
"$USER,media_manager"
"$USER,block_creator"
#"$USER,site_builder"
"$USER,block_manager"
)
count=0
DOMAINLIST=("lmn" "pdq" "xyz")
for SITE in "${DOMAINLIST[@]}"
do
echo "Creating account for $USER"
drush "@company-acsf."$SITE ucrt $USER --password="$PW" --mail="$USER"
while [ "x${USERLIST[count]}" != "x" ]
do
count=$(( $count + 1 ))
IFS=',' read -ra LINE <<< "${USERLIST[count]}"
USERNAME=${LINE[0]}
USERROLE=${LINE[1]}
if [[ -n "$USERNAME" && -n "$USERROLE" ]] ; then
echo "Updating account for $USERNAME with role \"$USERROLE\""
drush "@company-acsf."$SITE urol "${USERROLE}" $USERNAME
fi
done
done
exit 0
echostatement) in the inner loop does it get executed? With the right values? What values are actually being tested by the innermostif- are they what you'd expect?#!/bin/bashas the first line. Finally, don't mix[ ... ]and[[ ... ]]- use one or the other - and learn about[[ -z "$var" ]]instead of the ancient[ "x$var" = "x" ]thing.