<?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>MemoSoup &#187; shell</title>
	<atom:link href="http://www.memosoup.com/tag/shell/feed" rel="self" type="application/rss+xml" />
	<link>http://www.memosoup.com</link>
	<description>Mix of the things I always forget</description>
	<lastBuildDate>Tue, 07 Feb 2012 00:03:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Reading password in Unix shell</title>
		<link>http://www.memosoup.com/20100202/reading-password-in-unix-shell.html</link>
		<comments>http://www.memosoup.com/20100202/reading-password-in-unix-shell.html#comments</comments>
		<pubDate>Tue, 02 Feb 2010 21:18:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.memosoup.com/?p=256</guid>
		<description><![CDATA[print -n &#34;Enter Your password:&#34; stty_orig=`stty -g` trap &#34;stty ${stty_orig}; exit&#34; 1 2 3 15 stty -echo &#62;&#38;- 2&#62;&#38;- read PASS stty ${stty_orig} &#62;&#38;- 2&#62;&#38;- trap 1 2 3 15 print <p>trap :catches interruptions. I.e. if the user presses Ctrl+C, the normal stty mode is set before stopping the program stty -echo :switches off the [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">print <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Enter Your password:&quot;</span><br />
<span style="color: #007800;">stty_orig</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">stty</span> -g<span style="color: #000000; font-weight: bold;">`</span><br />
<span style="color: #7a0874; font-weight: bold;">trap</span> <span style="color: #ff0000;">&quot;stty <span style="color: #007800;">${stty_orig}</span>; exit&quot;</span> <span style="color: #000000;">1</span> <span style="color: #000000;">2</span> <span style="color: #000000;">3</span> <span style="color: #000000;">15</span><br />
<span style="color: #c20cb9; font-weight: bold;">stty</span> <span style="color: #660033;">-echo</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span>- <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span>-<br />
<span style="color: #c20cb9; font-weight: bold;">read</span> PASS <br />
<span style="color: #c20cb9; font-weight: bold;">stty</span> <span style="color: #800000;">${stty_orig}</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span>- <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span>-<br />
<span style="color: #7a0874; font-weight: bold;">trap</span> <span style="color: #000000;">1</span> <span style="color: #000000;">2</span> <span style="color: #000000;">3</span> <span style="color: #000000;">15</span><br />
print</div></div>
<p><strong>trap</strong>  :catches interruptions. I.e. if the user presses Ctrl+C, the normal stty mode is set before stopping the program<br />
<strong>stty -echo</strong>  :switches off the display echo<br />
<strong>&gt;&amp;- 2&gt;&amp;-</strong>  :helps to avoid <strong>&#8220;stty: Not a typewriter&#8221;</strong> message for non-interactive scripts.</p>
<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="zare366"><div style="float:left; width:100px; " class="zare366_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.memosoup.com%2F20100202%2Freading-password-in-unix-shell.html&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="zare366_google1"> 
				<g:plusone size="medium" href="http://www.memosoup.com/20100202/reading-password-in-unix-shell.html" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="zare366_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
					data-text="Reading password in Unix shell" data-url="http://www.memosoup.com/20100202/reading-password-in-unix-shell.html">Tweet</a> 
			</div></div>
		<div style="display:none;"><a href="http://www.news365live.com">news and informations</a>&nbsp;<a href="http://news365online.com">automotive,business,crime,health,life,politics,science,technology,travel</a><a href="http://worldnews365online.com">automotive,business,crime,health,life,politics,science,technology,travel</a></div><div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.memosoup.com/20100202/reading-password-in-unix-shell.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unix shell: workaround for loop problem</title>
		<link>http://www.memosoup.com/20100116/unix-shell-workaround-for-loop-problem.html</link>
		<comments>http://www.memosoup.com/20100116/unix-shell-workaround-for-loop-problem.html#comments</comments>
		<pubDate>Fri, 15 Jan 2010 23:04:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.memosoup.com/?p=247</guid>
		<description><![CDATA[<p>It&#8217;s not possible to get the value of the loop variables in some versions of ksh.</p> <p>Example:</p> #!/bin/ksh num=0 cat $0 &#124; while read line ; do &#160;let num=num+1 done echo &#34;Number=$num&#34; <p>This script will return &#8220;Number=0&#8243; as the result on some Linux machines.</p> <p>Here is the workaround for the problem: You should change the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s not possible to get the value of the loop variables in some versions of ksh.</p>
<p>Example:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/ksh</span><br />
<br />
<span style="color: #007800;">num</span>=<span style="color: #000000;">0</span><br />
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$0</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> line ; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp;<span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">num</span>=num+<span style="color: #000000;">1</span><br />
<span style="color: #000000; font-weight: bold;">done</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Number=<span style="color: #007800;">$num</span>&quot;</span></div></div>
<p>This script will return &#8220;Number=0&#8243; as the result on some Linux machines.</p>
<p>Here is the workaround for the problem: You should change the redirection method for the input file.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/ksh</span><br />
<br />
<span style="color: #007800;">l</span>=<span style="color: #000000;">0</span><br />
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> line ; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp;<span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">l</span>=l+<span style="color: #000000;">1</span><br />
<span style="color: #000000; font-weight: bold;">done</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$0</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Number=<span style="color: #007800;">$l</span>&quot;</span></div></div>
<p>The last script will return the correct result: &#8220;Number=9&#8243;</p>
<p>Another possibility is to use the named pipe:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/ksh</span><br />
<br />
<span style="color: #007800;">TMPPIPE</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>thepipe.<span style="color: #007800;">$$</span><br />
<span style="color: #c20cb9; font-weight: bold;">mkfifo</span> <span style="color: #007800;">$TMPPIPE</span><br />
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$0</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$TMPPIPE</span> <span style="color: #000000; font-weight: bold;">&amp;</span><br />
<span style="color: #007800;">num</span>=<span style="color: #000000;">0</span><br />
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> line ; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp;<span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">num</span>=num+<span style="color: #000000;">1</span><br />
<span style="color: #000000; font-weight: bold;">done</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$TMPPIPE</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Number=<span style="color: #007800;">$num</span>&quot;</span></div></div>
<div style="height:33px; padding-top:2px; padding-bottom:2px; clear:both;" class="zare366"><div style="float:left; width:100px; " class="zare366_facebook_like"> 
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.memosoup.com%2F20100116%2Funix-shell-workaround-for-loop-problem.html&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=27" 
					scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:27px;" allowTransparency="true"></iframe>
			</div><div style="float:left; width:90px; padding-left:10px;" class="zare366_google1"> 
				<g:plusone size="medium" href="http://www.memosoup.com/20100116/unix-shell-workaround-for-loop-problem.html" ></g:plusone>
			</div><div style="float:left; width:110px; padding-left:10px;" class="zare366_twitter"> 
				<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
					data-text="Unix shell: workaround for loop problem" data-url="http://www.memosoup.com/20100116/unix-shell-workaround-for-loop-problem.html">Tweet</a> 
			</div></div>
		<div style="display:none;"><a href="http://www.news365live.com">news and informations</a>&nbsp;<a href="http://news365online.com">automotive,business,crime,health,life,politics,science,technology,travel</a><a href="http://worldnews365online.com">automotive,business,crime,health,life,politics,science,technology,travel</a></div><div style="clear:both;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.memosoup.com/20100116/unix-shell-workaround-for-loop-problem.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

