<?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: Five Shell Programming Tips</title>
	<atom:link href="http://bashcurescancer.com/five_shell_programming_tips.html/feed" rel="self" type="application/rss+xml" />
	<link>http://bashcurescancer.com/five_shell_programming_tips.html</link>
	<description>Learn the UNIX/Linux command line</description>
	<lastBuildDate>Mon, 06 Jun 2011 01:35:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: rahul benegal</title>
		<link>http://bashcurescancer.com/five_shell_programming_tips.html/comment-page-1#comment-35225</link>
		<dc:creator>rahul benegal</dc:creator>
		<pubDate>Sun, 27 Dec 2009 06:10:25 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/five_shell_programming_tips.html#comment-35225</guid>
		<description>I&#039;d like to comment on point 3.


good_func can only return one value. Also, a sub-shell is created. If you call good_func in a loop, it can be very slow.

bad_func runs in the same shell. It can set multiple values. Typically, you can have a convention such as storing the result in RESULT. It runs faster in a loop.

In good_func which echoes the result, what happens if you are later debugging and add some echoes inside the prog. You must then be careful that you redirect your echo to stderr.</description>
		<content:encoded><![CDATA[<p>I&#8217;d like to comment on point 3.</p>
<p>good_func can only return one value. Also, a sub-shell is created. If you call good_func in a loop, it can be very slow.</p>
<p>bad_func runs in the same shell. It can set multiple values. Typically, you can have a convention such as storing the result in RESULT. It runs faster in a loop.</p>
<p>In good_func which echoes the result, what happens if you are later debugging and add some echoes inside the prog. You must then be careful that you redirect your echo to stderr.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bun</title>
		<link>http://bashcurescancer.com/five_shell_programming_tips.html/comment-page-1#comment-33388</link>
		<dc:creator>bun</dc:creator>
		<pubDate>Wed, 11 Nov 2009 03:47:21 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/five_shell_programming_tips.html#comment-33388</guid>
		<description>$ *nix philosophy: make each program do 1 thing well, causes:
1 small program
2 process creation is as cheap as possible
3 features aren&#039;t easily added to program
4 piping becomes the natural / intuitive way for ipc

$ the tips no 1,2,4 can be summarized to &quot;create process as necessary&quot;, this can be achieved in many ways (eg. using features 

of tool used, tweaking the pipeline)
- the maintainer of each tool considers many things before a feature is added to the tool, such as will it be used 

frequently?, does it offers much efficiency?
- no one is expected to remember all features (except the famous ones) of a tool unless he limits his area of expertise. 

however, each feature added till now is logically appropriate, i mean u can expect that grep has a feature that only output 

the num of matched line / diff can suppress its output &amp; only tell whether files are different. that&#039;s why i think doing 

optimization to a script is only done after the script has satisfied its functional requirement (up to this point the script 

is made in the intuitive way) &amp; only scripts that are heavily used treated this way. the fun part is that u can skip this 

boring task by making someone do it, cause it is simple
- tools&#039; maintainers tend to use the same opt char in controlling similar future (ex: for suppressing output, its either q / 

s)

$ tips no 3 isn&#039;t consistent with the others if what u&#039;re looking for is performance, it forks another subsh to do the func. 

a solution to this problem is to maintain a convention on the func identifier &amp; the var that stores the return val, just like 

maintaining convention of what a func do &amp; its identifier. example:
_mul(){
_MUL=$(($1*$2))
}
mul(){
echo _mul $1 $2
}

- this way u can store _MUL to a var / use it directly as long as access to _MUL is serialized

- try it with time: compare: time v=$(mul 2 3) with time { _mul 2 3; v=$_MUL; }

$ no 5 isn&#039;t a tip, &#039;read&#039; is important since it&#039;s the easiest &amp; cheapest (builtin) way, u can do v=$(&lt;/dev/stdin) / 

v=$(dd) with eof ending the input but it&#039;s just dumb unless u need a particular characteristic where &#039;read&#039; can&#039;t satisfy</description>
		<content:encoded><![CDATA[<p>$ *nix philosophy: make each program do 1 thing well, causes:<br />
1 small program<br />
2 process creation is as cheap as possible<br />
3 features aren&#8217;t easily added to program<br />
4 piping becomes the natural / intuitive way for ipc</p>
<p>$ the tips no 1,2,4 can be summarized to &#8220;create process as necessary&#8221;, this can be achieved in many ways (eg. using features </p>
<p>of tool used, tweaking the pipeline)<br />
- the maintainer of each tool considers many things before a feature is added to the tool, such as will it be used </p>
<p>frequently?, does it offers much efficiency?<br />
- no one is expected to remember all features (except the famous ones) of a tool unless he limits his area of expertise. </p>
<p>however, each feature added till now is logically appropriate, i mean u can expect that grep has a feature that only output </p>
<p>the num of matched line / diff can suppress its output &amp; only tell whether files are different. that&#8217;s why i think doing </p>
<p>optimization to a script is only done after the script has satisfied its functional requirement (up to this point the script </p>
<p>is made in the intuitive way) &amp; only scripts that are heavily used treated this way. the fun part is that u can skip this </p>
<p>boring task by making someone do it, cause it is simple<br />
- tools&#8217; maintainers tend to use the same opt char in controlling similar future (ex: for suppressing output, its either q / </p>
<p>s)</p>
<p>$ tips no 3 isn&#8217;t consistent with the others if what u&#8217;re looking for is performance, it forks another subsh to do the func. </p>
<p>a solution to this problem is to maintain a convention on the func identifier &amp; the var that stores the return val, just like </p>
<p>maintaining convention of what a func do &amp; its identifier. example:<br />
_mul(){<br />
_MUL=$(($1*$2))<br />
}<br />
mul(){<br />
echo _mul $1 $2<br />
}</p>
<p>- this way u can store _MUL to a var / use it directly as long as access to _MUL is serialized</p>
<p>- try it with time: compare: time v=$(mul 2 3) with time { _mul 2 3; v=$_MUL; }</p>
<p>$ no 5 isn&#8217;t a tip, &#8216;read&#8217; is important since it&#8217;s the easiest &amp; cheapest (builtin) way, u can do v=$(&lt;/dev/stdin) / </p>
<p>v=$(dd) with eof ending the input but it&#8217;s just dumb unless u need a particular characteristic where &#8216;read&#8217; can&#8217;t satisfy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://bashcurescancer.com/five_shell_programming_tips.html/comment-page-1#comment-31995</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Mon, 10 Aug 2009 01:43:37 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/five_shell_programming_tips.html#comment-31995</guid>
		<description>If you need to use xargs for filenames with spaces use the zero terminated format instead:
find . -type f -name &#039;mess*&#039; -exec grep -q &#039;Synergy&#039; {} \; -print0 &#124; xargs -0 rm -f</description>
		<content:encoded><![CDATA[<p>If you need to use xargs for filenames with spaces use the zero terminated format instead:<br />
find . -type f -name &#8216;mess*&#8217; -exec grep -q &#8216;Synergy&#8217; {} \; -print0 | xargs -0 rm -f</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://bashcurescancer.com/five_shell_programming_tips.html/comment-page-1#comment-26744</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Thu, 08 Jan 2009 06:53:42 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/five_shell_programming_tips.html#comment-26744</guid>
		<description>I agree with Joel&#039;s opinion. I believe the *nix philosophy is to use small, sharp tools. I mean, grep -c is definitely less intuitive than grep &#124; wc -l.

Then again, the information here does fit under the title &quot;Five Shell Programming __Tips__&quot;, I guess it&#039;s just that we should opt for the more intuitive use than some obscure command line arguments in most everyday usages.</description>
		<content:encoded><![CDATA[<p>I agree with Joel&#8217;s opinion. I believe the *nix philosophy is to use small, sharp tools. I mean, grep -c is definitely less intuitive than grep | wc -l.</p>
<p>Then again, the information here does fit under the title &#8220;Five Shell Programming __Tips__&#8221;, I guess it&#8217;s just that we should opt for the more intuitive use than some obscure command line arguments in most everyday usages.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://bashcurescancer.com/five_shell_programming_tips.html/comment-page-1#comment-918</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Fri, 21 Dec 2007 01:49:24 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/five_shell_programming_tips.html#comment-918</guid>
		<description>While I believe your opinion has merit, I disagree.  Also regarding the sticky bit, see the chmod manual:


STICKY FILES
On  older  Unix  systems,  the sticky bit caused executable files to be hoarded in swap space.  This feature is not useful on modern VM systems, and the Linux kernel ignores the sticky bit on files.  Other kernels may use the sticky bit on files for system-defined purposes.  On some systems, only the superuser can set the  sticky bit on files.</description>
		<content:encoded><![CDATA[<p>While I believe your opinion has merit, I disagree.  Also regarding the sticky bit, see the chmod manual:</p>
<p>STICKY FILES<br />
On  older  Unix  systems,  the sticky bit caused executable files to be hoarded in swap space.  This feature is not useful on modern VM systems, and the Linux kernel ignores the sticky bit on files.  Other kernels may use the sticky bit on files for system-defined purposes.  On some systems, only the superuser can set the  sticky bit on files.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joel</title>
		<link>http://bashcurescancer.com/five_shell_programming_tips.html/comment-page-1#comment-683</link>
		<dc:creator>Joel</dc:creator>
		<pubDate>Sun, 09 Dec 2007 17:59:06 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/five_shell_programming_tips.html#comment-683</guid>
		<description>Promoting grep -c &amp; -q encourages the proliferation of options in programs that don’t need them—how big is the cat(1) man page on your system?  If grep didn’t have all those extra options, maybe the clearer and more general grep &#124; wc would be faster yet!

(If it’s the program start-up time you’re concerned about, that’s what the sticky bit is for.)</description>
		<content:encoded><![CDATA[<p>Promoting grep -c &amp; -q encourages the proliferation of options in programs that don’t need them—how big is the cat(1) man page on your system?  If grep didn’t have all those extra options, maybe the clearer and more general grep | wc would be faster yet!</p>
<p>(If it’s the program start-up time you’re concerned about, that’s what the sticky bit is for.)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.209 seconds -->

