1

So I'm trying to write a small script that loops over an array list like so

if [ $EUID != 0 ]; then
   sudo "$0" "$@"
   exit $?
fi
echo "Please enter repo password"
stty -echo
read PASSWORD
stty echo
REPOS=("repo one" "repo 2" "repo 3")
for i in "${REPOS[@]}"
do
   sudo mount //$IPLOCATION/$i $MOUNTPATH/$i -o "username=$USERNAME,password=$PASSWORD"
done

This seems to work well when the array is REPOS=("repoone" "repotwo" "repothree") But not with spaces. I tried with repo\ one and repo\\\ one but am getting no luck. I know I'm missing something stupid.

1 Answers1

3

You need to put $i between double quotes:

sudo mount "//$IPLOCATION/$i" "$MOUNTPATH/$i" -o "username=$USERNAME,password=$PASSWORD"
zuazo
  • 3,042