Re: Bash scripts and multi-word filenames
On Sat, Aug 05, 2006 at 03:45:26PM +1000, John O'Hagan wrote:
> Hi,
>
> I keep running into this particular gap in my scripting, and hope someone can
> clear it up for me.
>
> FILES=$( ls SOMEWHERE ) #or find or grep, etc
>
> for FILE in $FILES; do SOMETHING; done
>
> I often find that if there are spaces in the names of anything in $FILES, the
> execution of SOMETHING occurs separately for each word in the name, producing
> unexpected results.
>
> Quoting doesn't seem to help. Are there ways to deal with this?
>
Hi John
You can overwrite Bashs internal field seperator variable (IFS) to
newline:
seb@zurich:~/test1$ IFS='
> '
seb@zurich:~/test1$ for f in `ls`; do echo $f; done
test
test 1
So Bash will stop treating whitespaces as list seperator.
Cheers Beat
Reply to: