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:


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


  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

  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


Leave a Reply

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

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

Facebook photo

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

Connecting to %s

%d bloggers like this: