我有一个脚本,在用户输入服务器名、用户名和密码后运行 python 脚本(用于通过 IMAP 删除重复电子邮件)。它的第一部分获取一个文件夹列表,第二部分然后将其用作输入 - 一切都很好,除非文件夹名称中有空格,此时条目需要用引号引起来作为示例,“收件箱”很好,而“我的收件箱”需要读取为“我的收件箱”
#!/bin/sh
# Delete all duplicate messages in all folders of said account.
# Note that we connect through SSL (-x) to the default port.
read -p "Server: " SERVER
read -p "Username: " USER
read -s -p "Password: " PASS
echo
echo ...........
echo FOLDER LIST
echo ...........
echo
# Next line generates list for display only
/tmp/IMAPdedup-master/imapdedup.py -s $SERVER -x -u $USER -w $PASS -l
# Next line generates list to be used by the do line - this is the entries that need
to have each line in quotations
for folder in `/tmp/IMAPdedup-master/imapdedup.py -s $SERVER -x -u $USER -w $PASS -l`;
do /tmp/IMAPdedup-master/imapdedup.py -s $SERVER -x -u $USER -w $PASS $folder
done
答案1
您不需要引用名称,您需要变量被引用。具体来说,为了使您的脚本正常工作,您需要将for folder in ...
循环替换为:
/tmp/IMAPdedup-master/imapdedup.py -s "$SERVER" -x -u "$USER" -w "$PASS" -l |
while IFS= read -r folder; do
/tmp/IMAPdedup-master/imapdedup.py -s "$SERVER" -x -u "$USER" -w "$PASS" "$folder"
done
我建议您阅读以下文章以了解原因: