所以我试图编写一个小脚本来循环数组列表,如下所示
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
当数组REPOS=("repoone" "repotwo" "repothree")
不带空格时,这似乎很有效。我尝试过repo\ one
andrepo\\\ one
但没有运气。我知道我错过了一些愚蠢的事情。
答案1
您需要$i
在双引号之间添加:
sudo mount "//$IPLOCATION/$i" "$MOUNTPATH/$i" -o "username=$USERNAME,password=$PASSWORD"