IFS Variable

$IFS is the linux delimiter character its used in for loops. $IFS by default just hold a space character, thus the for loop will iterate over items with spaces. Each space tells it its a new item. That’s a problem with files with spaces.

I recommend remembering this (this changes the for loop delimiter/IFS variable to a newline character so you can loop over things with spaces like windows filenames, then we set the variable back)

That will make it so that for loops can have newline characters as seperator/delimiters instead of spaces.

Here is a default situation where you DONT NEED TO CHANGE IFS:

That is fine, it will go over 1 2 3 4 5 no problem:

that is also fine

Example below where you need to change it. First I show the problem then the solution.

The Problem to Windows File Names Problem – default IFS

The Solution to Windows File Names Problem – changing IFS

Note: IFS doesnt just affect for loops, they also arent just used with space characters or newline characters. Sometimes you can use them for other things, check this article out: http://bash.cyberciti.biz/guide/$IFS

Leave a Reply

Your email address will not be published. Required fields are marked *