<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Writing Functions in Shell Script</title>
	<atom:link href="http://viralpatel.net/blogs/2009/07/writing-functions-in-shell-script.html/feed" rel="self" type="application/rss+xml" />
	<link>http://viralpatel.net/blogs/2009/07/writing-functions-in-shell-script.html</link>
	<description>Tutorials, Java, J2EE, Struts, AJAX, JavaScript, CSS, Web 2.0, MySQL, Articles</description>
	<lastBuildDate>Sat, 13 Mar 2010 19:36:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: spacebat</title>
		<link>http://viralpatel.net/blogs/2009/07/writing-functions-in-shell-script.html/comment-page-1#comment-9842</link>
		<dc:creator>spacebat</dc:creator>
		<pubDate>Fri, 10 Jul 2009 10:59:14 +0000</pubDate>
		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=1518#comment-9842</guid>
		<description>My method suffers from increased need for quoting (say the parameters have spaces, you might need to quote them and escape the quotes before passing to eval), also it won&#039;t work if the variable name you pass in is the same name as the local variable used to store the name, ie this is broken:

myfunc var &quot;holly&quot; &quot;wood&quot;

I&#039;ve never run into that problem in real life, but I&#039;ve been reading about it in the context of lisp macros where its known as variable capture. A workaround would be to prefix local vars with underscores.
Anyway at this point I tend to think heck this needs porting to perl or python :)</description>
		<content:encoded><![CDATA[<p>My method suffers from increased need for quoting (say the parameters have spaces, you might need to quote them and escape the quotes before passing to eval), also it won&#8217;t work if the variable name you pass in is the same name as the local variable used to store the name, ie this is broken:</p>
<p>myfunc var &#8220;holly&#8221; &#8220;wood&#8221;</p>
<p>I&#8217;ve never run into that problem in real life, but I&#8217;ve been reading about it in the context of lisp macros where its known as variable capture. A workaround would be to prefix local vars with underscores.<br />
Anyway at this point I tend to think heck this needs porting to perl or python :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Viral Patel</title>
		<link>http://viralpatel.net/blogs/2009/07/writing-functions-in-shell-script.html/comment-page-1#comment-9841</link>
		<dc:creator>Viral Patel</dc:creator>
		<pubDate>Fri, 10 Jul 2009 10:33:27 +0000</pubDate>
		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=1518#comment-9841</guid>
		<description>Hi spacebat.. I resolved the backslash issue. Thanks for the code.</description>
		<content:encoded><![CDATA[<p>Hi spacebat.. I resolved the backslash issue. Thanks for the code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: spacebat</title>
		<link>http://viralpatel.net/blogs/2009/07/writing-functions-in-shell-script.html/comment-page-1#comment-9840</link>
		<dc:creator>spacebat</dc:creator>
		<pubDate>Fri, 10 Jul 2009 10:23:53 +0000</pubDate>
		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=1518#comment-9840</guid>
		<description>Damn, it backslashed all the quotes and backslashes :\</description>
		<content:encoded><![CDATA[<p>Damn, it backslashed all the quotes and backslashes :\</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: spacebat</title>
		<link>http://viralpatel.net/blogs/2009/07/writing-functions-in-shell-script.html/comment-page-1#comment-9839</link>
		<dc:creator>spacebat</dc:creator>
		<pubDate>Fri, 10 Jul 2009 10:22:30 +0000</pubDate>
		<guid isPermaLink="false">http://viralpatel.net/blogs/?p=1518#comment-9839</guid>
		<description>Capturing echoed output is fairly useful, but then obtaining the success or failure of the function can get tricky. I might write it like this:

myfunc() {
  local var=$1
  eval $var=&quot;$2$3&quot;
}

This makes it handy to test the return value of a function that might fail:
if myfunc value &quot;holly&quot; &quot;wood&quot;; then
    echo &quot;$value beckons!&quot;
else
    echo woe is me
fi</description>
		<content:encoded><![CDATA[<p>Capturing echoed output is fairly useful, but then obtaining the success or failure of the function can get tricky. I might write it like this:</p>
<p>myfunc() {<br />
  local var=$1<br />
  eval $var=&quot;$2$3&quot;<br />
}</p>
<p>This makes it handy to test the return value of a function that might fail:<br />
if myfunc value &quot;holly&quot; &quot;wood&quot;; then<br />
    echo &quot;$value beckons!&quot;<br />
else<br />
    echo woe is me<br />
fi</p>
]]></content:encoded>
	</item>
</channel>
</rss>
