Sensible handling of filenames with blanks (in bash scripts)

To make your bash script handle filenames with blanks better just put the following in a line above your file handling code:

IFS=$'n'

This tells bash to interprete only newlines as file seperators. Useful for grep, find, etc. as parameters of a for-loop. Obviously not very helpful if you have multiple file names in a line.

Found in the BSD-Team Dresden Wiki

Leave a comment

2 Comments

  1. anonymous

     /  April 24, 2009

    Stefan.Marx@marx-consulting.COM writes:

    Hi Raphael,thanks a very lot! Saved me a couple of 10 minutes of character replacement in my Java code.Quite elegant hack by the way ;=).Greetings from Cologne, Germany,cu Stefan

    Reply
  2. anonymous

     /  March 15, 2011

    Anonym writes:perfect!used it with svn status (outputs status, a lot of blanks and then the filename)Danke schön!Greetings from KA

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: