<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stefan Sobek Blog &#187; shellscript</title>
	<atom:link href="http://www.sobek.info/blog/tag/shellscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sobek.info/blog</link>
	<description>Writing about IT, Software Engineering, sports and other stuff</description>
	<lastBuildDate>Mon, 24 Jan 2011 12:50:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Linux, Unix, Mac &#8211; Loop filenames with spaces</title>
		<link>http://www.sobek.info/blog/2010/05/10/linux-unix-mac-loop-filenames-with-spaces/</link>
		<comments>http://www.sobek.info/blog/2010/05/10/linux-unix-mac-loop-filenames-with-spaces/#comments</comments>
		<pubDate>Mon, 10 May 2010 14:23:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[loop filenames]]></category>
		<category><![CDATA[shellscript]]></category>
		<category><![CDATA[spaces in linux filenames]]></category>

		<guid isPermaLink="false">http://www.sobek.info/blog/?p=272</guid>
		<description><![CDATA[Situation 
You want to operate on a linux, unix or mac system some files in a bash script and do some file operations like modifying the text content or moving the files to another location depending on the filename, content or another mathinc pattern. 
Problem 
Wondered why you have problems with windows files in a [...]]]></description>
			<content:encoded><![CDATA[<h5>Situation </h5>
<p>You want to operate on a linux, unix or mac system some files in a bash script and do some file operations like modifying the text content or moving the files to another location depending on the filename, content or another mathinc pattern. </p>
<h5>Problem </h5>
<p>Wondered why you have problems with windows files in a network when looping over them? Linux takes whitespaces in file name as line separator so that echoing the file will cause a separate line and so you cannot operate on this file. </p>
<h5>Solution </h5>
<p>I guess it is called <strong>Instruction Field Separator</strong> or something. You have to set this only to line break and not to whitespaces. First save the old variable content, then set the new content so that the bash do not takes whitespaces as line separators</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p272code2'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2722"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p272code2"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">OLDIFS</span>=<span style="color: #007800;">$IFS</span>
<span style="color: #007800;">IFS</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-en</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>\b&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> FILE <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.txt)
do
   echo $FILE
done
&nbsp;
$IFS = $OLDIFS</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.sobek.info/blog/2010/05/10/linux-unix-mac-loop-filenames-with-spaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

