On Tue, Jul 26, 2011 at 02:40, Mark Neyhart <mark_neyh...@legis.state.ak.us> wrote: > Bill M wrote: > >> FILES=/home/bill/.icedove/qjimvr85.default/Mail/Local\ >> Folders/2-Personal.sbd/* >> # or "/home/bill/.icedove/qjimvr85.default/Mail/Local >> Folders/2-Personal.sbd/*" >> >> for i in $FILES [...] > > This appears to be related to the default value of the BASH internal > variable $IFS (internal field separator). It defaults to whitespace, > which includes the space character. The for loop interprets the space > inside $FILES as a field separator. Try setting $IFS to ONLY new line > above the for loop. > > IFS=$'\n' > for i in $FILES
The problem as Mark has correctly pointed out is this line. Since $FILES is not quoted, bash will expand it and then split on IFS. If you are on an ext? file system the only safe separator for filenames is the null byte '\0', unless you can guarantee somehow that your script will never see a file with a newline in the name. Thus, I'd recommend not using IFS for this purpose. Two possible more robust solutions exist: 1. Just use the shell's globbing - it was meant for this purpose - instead of assigning a glob to a variable. Glob expansions can be iterated over in loops correctly and safely. Expanded strings are much more tricky to get right (if it is even possible) and less safe when you don't. FILES="/home/bill/.../Local Folders/2-Personal.sbd" for i in "$FILES"/* note the glob is outside the quotes 2. Use find with it's own exec options or xargs. I suggested this second b/c it is more complicated, depends on an external command, and the first does what you need, so why bother with this one? :-) 3. Ok I lied, there's a third: you could use BASH(-only) arrays, but since you are working with files anyways it basically comes down to doing #1 less portably and with more syntax. >> do >> mv "$i" ""$i".saved" >> formail -D 65536 .msgid.cache -s < ""$i".saved" > "$i" what's with the double double quotes "" ? typo? -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/can0j2y6opzabavrnvryy6zaqljii7s9_4xys-qaxpzb8gsa...@mail.gmail.com