2

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"

#!/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
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

4

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

I suggest you read the following posts to understand why:

terdon
  • 242,166