![在数组上循环安装(名称有空格)](https://linux22.com/image/86509/%E5%9C%A8%E6%95%B0%E7%BB%84%E4%B8%8A%E5%BE%AA%E7%8E%AF%E5%AE%89%E8%A3%85%EF%BC%88%E5%90%8D%E7%A7%B0%E6%9C%89%E7%A9%BA%E6%A0%BC%EF%BC%89.png)
所以我试图编写一个小脚本来循环数组列表,如下所示
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"