I have a script that runs a python script (used to deduplicate emails via IMAP) after a user has entered a servername, username & password. The first part of it gets a list of folders which the second part then uses as inputs - all fine unless a folder name has a space in it at which point the entry needs to be in quotation marks As an example Inbox is fine whereas My Inbox needs to be read as "My Inbox"

# 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 ...........

# 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


You don't need the names to be quoted, you need the variables to be quoted. Specifically, to make your script work, you need to replace the for folder in ... loop with:

/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"

I suggest you read the following posts to understand why:

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.