<?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>DALLASCAO.COM</title>
	<atom:link href="http://dallascao.com/en/feed/" rel="self" type="application/rss+xml" />
	<link>http://dallascao.com/en</link>
	<description>Site of Dallas Cao, English to Chinese translator</description>
	<lastBuildDate>Sun, 19 May 2013 06:27:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Test if a variable is number in bash</title>
		<link>http://dallascao.com/en/test-if-a-variable-is-number-in-bash/</link>
		<comments>http://dallascao.com/en/test-if-a-variable-is-number-in-bash/#comments</comments>
		<pubDate>Sun, 19 May 2013 06:15:24 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">http://dallascao.com/en/?p=987</guid>
		<description><![CDATA[Among the solutions provided at stackoverflow.com, I like this one the most: var=a &#160; if &#91; &#34;$var&#34; -eq &#34;$var&#34; &#93; 2&#62;/dev/null; then echo number else echo not a number fi 2 means the standard error output. If $var is a number, [ "$var" -eq "$var" ] will not output and error message. And an error [...]]]></description>
				<content:encoded><![CDATA[<p>Among the solutions provided at <a href='http://stackoverflow.com/questions/806906/how-do-i-test-if-a-variable-is-a-number-in-bash/819955#819955'>stackoverflow.com</a>, I like this one the most:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">var</span>=a
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$var</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$var</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> number
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> not a number
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>2 means the standard error output. If $var is a number, [ "$var" -eq "$var" ] will not output and error message. And an error message will occur when $var is not a number. </p>
<p>This brings out something interesting that I didn&#8217;t know before.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">if</span> somenonsense <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> no error message
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> some error mesage
    <span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>The output is &#8220;some error message&#8221;.<br />
This is easy to understand. As &#8220;somenonsense&#8221; is not a command or a program, it will output an error message</p>
<p>But&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">var1</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">var2</span>=<span style="color: #000000;">2</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$var1</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$var2</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> no error message
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> some error message
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>The output is &#8220;not equal&#8221;. Why? I don&#8217;t know. It seems illogical as this time [ "$var1" -eq "$var2" ] will not output any error message. If you know why please let me know.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://dallascao.com/en/curl-failure-empty-responses/" rel="bookmark" class="crp_title">curl failure: Empty responses</a></li><li><a href="http://dallascao.com/en/sed-regular-expressions/" rel="bookmark" class="crp_title">sed regular expressions</a></li><li><a href="http://dallascao.com/en/?post_type=wpcf7_contact_form&p=824" rel="bookmark" class="crp_title">Contact form 1</a></li><li><a href="http://dallascao.com/en/use-sed-to-extract-a-substring-using-regular-expressions/" rel="bookmark" class="crp_title">use sed to extract a substring using regular expressions</a></li><li><a href="http://dallascao.com/en/quick-solution-to-pureftpd-553-error/" rel="bookmark" class="crp_title">Quick solution to Pureftpd 553 error</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdallascao.com%2Fen%2Ftest-if-a-variable-is-number-in-bash%2F&amp;title=Test%20if%20a%20variable%20is%20number%20in%20bash"><img src="/en/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://dallascao.com/en/test-if-a-variable-is-number-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chang the swap behavior of linux</title>
		<link>http://dallascao.com/en/chang-the-swap/</link>
		<comments>http://dallascao.com/en/chang-the-swap/#comments</comments>
		<pubDate>Sat, 11 May 2013 03:42:30 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[Coding Frenzy]]></category>

		<guid isPermaLink="false">http://dallascao.com/en/?p=985</guid>
		<description><![CDATA[The default swappiness is 60. It can be 0-100, with the bigger value more pages will be swapped to harddisk from memory. If you want to use more physical memory and less swap, decrease the number. echo 40 &#62; /proc/sys/vm/swappiness Related Posts:Test if a variable is number in bashinstall/upgrade to the latest version of nodejsnode [...]]]></description>
				<content:encoded><![CDATA[<p>The default swappiness is 60. It can be 0-100, with the bigger value more pages will be swapped to harddisk from memory.<br />
If you want to use more physical memory and less swap, decrease the number.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">40</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>vm<span style="color: #000000; font-weight: bold;">/</span>swappiness</pre></div></div>

<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://dallascao.com/en/test-if-a-variable-is-number-in-bash/" rel="bookmark" class="crp_title">Test if a variable is number in bash</a></li><li><a href="http://dallascao.com/en/installupgrade-to-the-latest-version-of-nodejs/" rel="bookmark" class="crp_title">install/upgrade to the latest version of nodejs</a></li><li><a href="http://dallascao.com/en/node-quick-install/" rel="bookmark" class="crp_title">node quick install</a></li><li><a href="http://dallascao.com/en/curl-failure-empty-responses/" rel="bookmark" class="crp_title">curl failure: Empty responses</a></li><li><a href="http://dallascao.com/en/sed-regular-expressions/" rel="bookmark" class="crp_title">sed regular expressions</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdallascao.com%2Fen%2Fchang-the-swap%2F&amp;title=Chang%20the%20swap%20behavior%20of%20linux"><img src="/en/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://dallascao.com/en/chang-the-swap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What you may not know about linux sed</title>
		<link>http://dallascao.com/en/what-you-may-not-know-about-linux-sed/</link>
		<comments>http://dallascao.com/en/what-you-may-not-know-about-linux-sed/#comments</comments>
		<pubDate>Wed, 08 May 2013 03:51:07 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[Coding Frenzy]]></category>

		<guid isPermaLink="false">http://dallascao.com/en/?p=982</guid>
		<description><![CDATA[1. Separator can be any symbol. This also works: echo '/etc/python3/dummy' &#124; sed 's&#124;/etc/python3/&#124;/etc/python2/&#124;' output: /etc/python2/dummy In this example above I used &#124; to replace the normally used separator / Related Posts:Two ways to write literal strings containing line breaks to a fileTest if a variable is number in bashsed regular expressionsinstall/upgrade to the latest [...]]]></description>
				<content:encoded><![CDATA[<p>1. Separator can be any symbol.</p>
<p>This also works:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'/etc/python3/dummy'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s|/etc/python3/|/etc/python2/|'</span></pre></div></div>

<p>output:
<pre>/etc/python2/dummy</pre>
<p>In this example above I used | to replace the normally used separator /</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://dallascao.com/en/two-ways-to-write-literal-strings-containing-line-breaks-to-a-file/" rel="bookmark" class="crp_title">Two ways to write literal strings containing line breaks to a file</a></li><li><a href="http://dallascao.com/en/test-if-a-variable-is-number-in-bash/" rel="bookmark" class="crp_title">Test if a variable is number in bash</a></li><li><a href="http://dallascao.com/en/sed-regular-expressions/" rel="bookmark" class="crp_title">sed regular expressions</a></li><li><a href="http://dallascao.com/en/installupgrade-to-the-latest-version-of-nodejs/" rel="bookmark" class="crp_title">install/upgrade to the latest version of nodejs</a></li><li><a href="http://dallascao.com/en/curl-failure-empty-responses/" rel="bookmark" class="crp_title">curl failure: Empty responses</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdallascao.com%2Fen%2Fwhat-you-may-not-know-about-linux-sed%2F&amp;title=What%20you%20may%20not%20know%20about%20linux%20sed"><img src="/en/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://dallascao.com/en/what-you-may-not-know-about-linux-sed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two ways to write literal strings containing line breaks to a file</title>
		<link>http://dallascao.com/en/two-ways-to-write-literal-strings-containing-line-breaks-to-a-file/</link>
		<comments>http://dallascao.com/en/two-ways-to-write-literal-strings-containing-line-breaks-to-a-file/#comments</comments>
		<pubDate>Tue, 07 May 2013 06:41:23 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[Coding Frenzy]]></category>

		<guid isPermaLink="false">http://dallascao.com/en/?p=978</guid>
		<description><![CDATA[1. Use printf printf &#34;line 1 line2 line 3 containing a variable: ${PWD} line 4 contains a quote mark ' and \&#34; &#34;&#62;temp.txt &#160; cat temp.txt Notice double quote &#8221; needs to be escaped. 2. Use Here Doc: cat &#62; temp.txt &#60;&#60;EOF line 1 line2 line 3 containing a variable: ${PWD} line 4 contains a [...]]]></description>
				<content:encoded><![CDATA[<p>1. Use printf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;line 1
line2
line 3 containing a variable: <span style="color: #007800;">${PWD}</span>
line 4 contains a quote mark ' and <span style="color: #000099; font-weight: bold;">\&quot;</span>
&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>temp.txt
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> temp.txt</pre></div></div>

<p>Notice double quote &#8221; needs to be escaped.</p>
<p>2. Use Here Doc:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;</span> temp.txt <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOF
line 1
line2
line 3 containing a variable: ${PWD}
line 4 contains a quote mark ' and &quot;
EOF</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> temp.txt</pre></div></div>

<p>Notice double quote &#8221; doesn&#8217;t need to be escaped.</p>
<p>Also notice &#8220;EOF&#8221; can actually be anything. This also works</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;</span> temp.txt <span style="color: #cc0000; font-style: italic;">&lt;&lt;SEPARATOR
line 1
line2
line 3 containing a variable: ${PWD}
line 4 contains a quote mark ' and &quot;
SEPARATOR</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> temp.txt</pre></div></div>

<p>Notice double quote &#8221; doesn&#8217;t need to be escaped.</p>
<p>http://en.wikipedia.org/wiki/Here_document#Unix-Shells</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://dallascao.com/en/clean-up-dd-wrt-nvram/" rel="bookmark" class="crp_title">clean up dd-wrt nvram</a></li><li><a href="http://dallascao.com/en/sed-regular-expressions/" rel="bookmark" class="crp_title">sed regular expressions</a></li><li><a href="http://dallascao.com/en/use-variable-values-as-part-of-a-variable-name/" rel="bookmark" class="crp_title">Use variable values as part of a variable name</a></li><li><a href="http://dallascao.com/en/randomly-select-a-line-from-a-file/" rel="bookmark" class="crp_title">Bash: Randomly select a line from a file</a></li><li><a href="http://dallascao.com/en/use-sed-to-extract-a-substring-using-regular-expressions/" rel="bookmark" class="crp_title">use sed to extract a substring using regular expressions</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdallascao.com%2Fen%2Ftwo-ways-to-write-literal-strings-containing-line-breaks-to-a-file%2F&amp;title=Two%20ways%20to%20write%20literal%20strings%20containing%20line%20breaks%20to%20a%20file"><img src="/en/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://dallascao.com/en/two-ways-to-write-literal-strings-containing-line-breaks-to-a-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>split string in Bash</title>
		<link>http://dallascao.com/en/split-string/</link>
		<comments>http://dallascao.com/en/split-string/#comments</comments>
		<pubDate>Tue, 07 May 2013 06:23:34 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">http://dallascao.com/en/?p=976</guid>
		<description><![CDATA[emails=&#34;email1@gmail.com;email2@gmail.com;email3@gmail.com&#34; emails=${emails//;/ } #replace ; with space arr_emails=&#40;$emails&#41; # put them into an array for item in ${arr_emails[@]}; do echo $item done In fact this works also. You don&#8217;t really need arrays emails=&#34;email1@gmail.com;email2@gmail.com;email3@gmail.com&#34; emails=${emails//;/ } #replace ; with space for item in $emails; do echo $item done But with using arrays, you can do many [...]]]></description>
				<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">emails</span>=<span style="color: #ff0000;">&quot;email1@gmail.com;email2@gmail.com;email3@gmail.com&quot;</span>
<span style="color: #007800;">emails</span>=<span style="color: #800000;">${emails//;/ }</span> <span style="color: #666666; font-style: italic;">#replace ; with space</span>
<span style="color: #007800;">arr_emails</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$emails</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #666666; font-style: italic;"># put them into an array</span>
<span style="color: #000000; font-weight: bold;">for</span> item <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${arr_emails[@]}</span>; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$item</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>In fact this works also. You don&#8217;t really need arrays</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">emails</span>=<span style="color: #ff0000;">&quot;email1@gmail.com;email2@gmail.com;email3@gmail.com&quot;</span>
<span style="color: #007800;">emails</span>=<span style="color: #800000;">${emails//;/ }</span> <span style="color: #666666; font-style: italic;">#replace ; with space</span>
<span style="color: #000000; font-weight: bold;">for</span> item <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$emails</span>; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$item</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>But with using arrays, you can do many other operations http://www.thegeekstuff.com/2010/06/bash-array-tutorial/</p>
<p>For the bash or sh version that &#8220;emails=${emails//;/ } &#8221; doesn&#8217;t work, use tr command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">emails</span>=<span style="color: #ff0000;">&quot;email1@gmail.com;email2@gmail.com;email3@gmail.com&quot;</span>
<span style="color: #007800;">emails</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$emails</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">&quot;;&quot;</span> <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">for</span> item <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$emails</span>; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$item</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>This also works:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">emails</span>=<span style="color: #ff0000;">&quot;email1@gmail.com;email2@gmail.com;email3@gmail.com&quot;</span>
<span style="color: #007800;">emails</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$emails</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">&quot;;&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">for</span> item <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$emails</span>; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$item</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://dallascao.com/en/sed-regular-expressions/" rel="bookmark" class="crp_title">sed regular expressions</a></li><li><a href="http://dallascao.com/en/test-if-a-variable-is-number-in-bash/" rel="bookmark" class="crp_title">Test if a variable is number in bash</a></li><li><a href="http://dallascao.com/en/curl-failure-empty-responses/" rel="bookmark" class="crp_title">curl failure: Empty responses</a></li><li><a href="http://dallascao.com/en/how-to-monitor-node-js-using-bash-script/" rel="bookmark" class="crp_title">How to monitor node.js using bash script</a></li><li><a href="http://dallascao.com/en/use-sed-to-extract-a-substring-using-regular-expressions/" rel="bookmark" class="crp_title">use sed to extract a substring using regular expressions</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdallascao.com%2Fen%2Fsplit-string%2F&amp;title=split%20string%20in%20Bash"><img src="/en/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://dallascao.com/en/split-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sed regular expressions</title>
		<link>http://dallascao.com/en/sed-regular-expressions/</link>
		<comments>http://dallascao.com/en/sed-regular-expressions/#comments</comments>
		<pubDate>Sat, 04 May 2013 13:50:14 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">http://dallascao.com/en/?p=970</guid>
		<description><![CDATA[echo 'iweigh297lbs' &#124; sed 's/.*[^0-9]\([0-9]\+\).*/\1/' The expression has to match the whole line. Greed: The expression will match the largest possible from left to right. This won&#8217;t work. echo 'iweigh297lbs' &#124; sed 's/.*\([0-9]\+\).*/\1/' Output 7 This won&#8217;t work echo 'iweigh297lbs' &#124; sed 's/.*[^0-9]\([0-9]*\).*/\1/' This works echo 'iweigh297lbs' &#124; sed 's/.*[^0-9]\([0-9][0-9]*\).*/\1/' + has to be escaped. [...]]]></description>
				<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'iweigh297lbs'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/.*[^0-9]\([0-9]\+\).*/\1/'</span></pre></div></div>

<p>The expression has to match the whole line.<br />
Greed: The expression will match the largest possible from left to right.<br />
This won&#8217;t work.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'iweigh297lbs'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/.*\([0-9]\+\).*/\1/'</span></pre></div></div>

<p>Output 7</p>
<p>This won&#8217;t work</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'iweigh297lbs'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/.*[^0-9]\([0-9]*\).*/\1/'</span></pre></div></div>

<p>This works</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'iweigh297lbs'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/.*[^0-9]\([0-9][0-9]*\).*/\1/'</span></pre></div></div>

<p>+ has to be escaped. * should not be escaped.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://dallascao.com/en/use-sed-to-extract-a-substring-using-regular-expressions/" rel="bookmark" class="crp_title">use sed to extract a substring using regular expressions</a></li><li><a href="http://dallascao.com/en/test-if-a-variable-is-number-in-bash/" rel="bookmark" class="crp_title">Test if a variable is number in bash</a></li><li><a href="http://dallascao.com/en/split-string/" rel="bookmark" class="crp_title">split string in Bash</a></li><li><a href="http://dallascao.com/en/curl-failure-empty-responses/" rel="bookmark" class="crp_title">curl failure: Empty responses</a></li><li><a href="http://dallascao.com/en/how-to-monitor-node-js-using-bash-script/" rel="bookmark" class="crp_title">How to monitor node.js using bash script</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdallascao.com%2Fen%2Fsed-regular-expressions%2F&amp;title=sed%20regular%20expressions"><img src="/en/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://dallascao.com/en/sed-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to run chrome from command line</title>
		<link>http://dallascao.com/en/how-to-run-chrome-from-command-line/</link>
		<comments>http://dallascao.com/en/how-to-run-chrome-from-command-line/#comments</comments>
		<pubDate>Thu, 25 Apr 2013 14:16:47 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[Coding Frenzy]]></category>

		<guid isPermaLink="false">http://dallascao.com/en/?p=967</guid>
		<description><![CDATA[YOu need first add the chrome.exe directory to windows environment. &#91;Environment&#93;::SetEnvironmentVariable&#40;&#34;Path&#34;, &#34;$env:Path;C:\Program Files (x86)\Google\Chrome\Application&#34;, &#34;User&#34;&#41; Related Posts:Script works under command line but not in crontab?Run at startup using CRONBuild a Shadowsocks server &#8211; an easier alternative to VPNBash Script to get script pathCannot ping VPS&#8217;s own IP or localhostPowered by Contextual Related Posts]]></description>
				<content:encoded><![CDATA[<p>YOu need first add the chrome.exe directory to windows environment.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>Environment<span style="color: #7a0874; font-weight: bold;">&#93;</span>::SetEnvironmentVariable<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;Path&quot;</span>, <span style="color: #ff0000;">&quot;<span style="color: #007800;">$env</span>:Path;C:\Program Files (x86)\Google\Chrome\Application&quot;</span>, <span style="color: #ff0000;">&quot;User&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://dallascao.com/en/script-works-under-command-line-but-not-in-crontab/" rel="bookmark" class="crp_title">Script works under command line but not in crontab?</a></li><li><a href="http://dallascao.com/en/run-at-startup-using-cron/" rel="bookmark" class="crp_title">Run at startup using CRON</a></li><li><a href="http://dallascao.com/en/build-a-shadowsocks-server-an-easier-alternative-to-vpn/" rel="bookmark" class="crp_title">Build a Shadowsocks server &#8211; an easier alternative to VPN</a></li><li><a href="http://dallascao.com/en/bash-script-to-get-script-path/" rel="bookmark" class="crp_title">Bash Script to get script path</a></li><li><a href="http://dallascao.com/en/cannot-ping-vpss-own-ip-or-localhost/" rel="bookmark" class="crp_title">Cannot ping VPS&#8217;s own IP or localhost</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdallascao.com%2Fen%2Fhow-to-run-chrome-from-command-line%2F&amp;title=How%20to%20run%20chrome%20from%20command%20line"><img src="/en/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://dallascao.com/en/how-to-run-chrome-from-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sudo: allow non-root users run certain commands</title>
		<link>http://dallascao.com/en/sudo-allow-non-root-users-run-certain-commands/</link>
		<comments>http://dallascao.com/en/sudo-allow-non-root-users-run-certain-commands/#comments</comments>
		<pubDate>Wed, 17 Apr 2013 16:23:08 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">http://dallascao.com/en/?p=964</guid>
		<description><![CDATA[Allow user www-data to run ps www-data ALL = NOPASSWD: /bin/ps Related Posts:iptables study noteclean up dd-wrt nvramStep by step LNMP installation guide for CentoOS serversHow to run chrome from command linesed regular expressionsPowered by Contextual Related Posts]]></description>
				<content:encoded><![CDATA[<p>Allow user www-data to run ps</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">www-data ALL = NOPASSWD: <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ps</span></pre></div></div>

<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://dallascao.com/en/iptables-study-note/" rel="bookmark" class="crp_title">iptables study note</a></li><li><a href="http://dallascao.com/en/clean-up-dd-wrt-nvram/" rel="bookmark" class="crp_title">clean up dd-wrt nvram</a></li><li><a href="http://dallascao.com/en/vps-step-by-step/" rel="bookmark" class="crp_title">Step by step LNMP installation guide for CentoOS servers</a></li><li><a href="http://dallascao.com/en/how-to-run-chrome-from-command-line/" rel="bookmark" class="crp_title">How to run chrome from command line</a></li><li><a href="http://dallascao.com/en/sed-regular-expressions/" rel="bookmark" class="crp_title">sed regular expressions</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdallascao.com%2Fen%2Fsudo-allow-non-root-users-run-certain-commands%2F&amp;title=sudo%3A%20allow%20non-root%20users%20run%20certain%20commands"><img src="/en/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://dallascao.com/en/sudo-allow-non-root-users-run-certain-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script works under command line but not in crontab?</title>
		<link>http://dallascao.com/en/script-works-under-command-line-but-not-in-crontab/</link>
		<comments>http://dallascao.com/en/script-works-under-command-line-but-not-in-crontab/#comments</comments>
		<pubDate>Sat, 30 Mar 2013 05:12:17 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[Coding Frenzy]]></category>

		<guid isPermaLink="false">http://dallascao.com/en/?p=960</guid>
		<description><![CDATA[Add the following lines to crontab and then it will work: SHELL=/bin/bash PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games Related Posts:Run at startup using CRONCentOS website backup shell scriptsHow to monitor node.js using bash scriptHow to run chrome from command linenode process monitorPowered by Contextual Related Posts]]></description>
				<content:encoded><![CDATA[<p>Add the following lines to crontab and then it will work:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">SHELL</span>=<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span>
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>lightdm<span style="color: #000000; font-weight: bold;">/</span>lightdm:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>games</pre></div></div>

<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://dallascao.com/en/run-at-startup-using-cron/" rel="bookmark" class="crp_title">Run at startup using CRON</a></li><li><a href="http://dallascao.com/en/centos-website-backup-shell-scripts/" rel="bookmark" class="crp_title">CentOS website backup shell scripts</a></li><li><a href="http://dallascao.com/en/how-to-monitor-node-js-using-bash-script/" rel="bookmark" class="crp_title">How to monitor node.js using bash script</a></li><li><a href="http://dallascao.com/en/how-to-run-chrome-from-command-line/" rel="bookmark" class="crp_title">How to run chrome from command line</a></li><li><a href="http://dallascao.com/en/node-process-monitor/" rel="bookmark" class="crp_title">node process monitor</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdallascao.com%2Fen%2Fscript-works-under-command-line-but-not-in-crontab%2F&amp;title=Script%20works%20under%20command%20line%20but%20not%20in%20crontab%3F"><img src="/en/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://dallascao.com/en/script-works-under-command-line-but-not-in-crontab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build a Shadowsocks server &#8211; an easier alternative to VPN</title>
		<link>http://dallascao.com/en/build-a-shadowsocks-server-an-easier-alternative-to-vpn/</link>
		<comments>http://dallascao.com/en/build-a-shadowsocks-server-an-easier-alternative-to-vpn/#comments</comments>
		<pubDate>Sun, 24 Mar 2013 15:52:15 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">http://dallascao.com/en/?p=958</guid>
		<description><![CDATA[Hi everyone, Last time I wrote a tutorial on how to build an PPTP server. Now a new way to connect emerged: Shadowsocks! Shadowsocks is already a hot topic among some Chinese-speaking communities but still largely unknown to the expats I think. Here we go: the first tutorial on building a shadowsocks server in English! [...]]]></description>
				<content:encoded><![CDATA[<p>Hi everyone,</p>
<p>Last time I wrote a tutorial on <a href="http://www.shanghaiexpat.com/phpbbforum/the-easiest-way-to-build-your-own-vpn-server-t139310.html">how to build an PPTP server</a>. Now a new way to connect emerged: Shadowsocks! Shadowsocks is already a hot topic among some Chinese-speaking communities but still largely unknown to the expats I think. Here we go: the first tutorial on building a shadowsocks server in English!</p>
<p>After finishing this tutorial you should be able to visit blocked websites on your Windows computer using your own Shadowsocks system.</p>
<p>Shadowsocks is a creation by clowwindy.</p>
<p><strong>Step one: First get a VPS</strong></p>
<p>Get a Linux VPS. A VPS is shortened for Virtual Private Server. It&#8217;s not a whole machine (too costly!) but one portion of a machine. A 256 Ram VPS is about 60-90 USD a year and that&#8217;s all you have to pay. And if you manage to sell your shadowsocks accounts, you can even make profits!</p>
<p>For China users, <a href='http://www.vr.org/cloud-locations?a=2819'>vr.org</a> offers the best Hong Kong VPS servers.</p>
<p>A decent VPS provider is <a href="http://www.linode.com/?r=3d521c392de98476f1617c4990593be4ae14962d">linode.com</a> which provides Japan and US servers fast for China.</p>
<p>A cheaper choice is <a href="https://www.budgetvm.com/account/aff.php?aff=184">budgetvm.com</a></p>
<p>You need to get a VPS with linux centos, Debian or Ubuntu installed. After purchasing you will get an IP for your VPS, and a SSH (never mind those terms. Few knows what they actually are) account.</p>
<p><strong>Step two: install Shadowsocks server application on your VPS</strong></p>
<p>Use Putty (software name) to log on to your remote VPS using the IP and SSH account provided. And you get a DOS like black Window with a command line like this:</p>
<p><img class="alignnone" alt="" src="https://breakwall.net/promo/remote_command_line.png" width="341" height="171" /></p>
<p>Type at the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> https:<span style="color: #000000; font-weight: bold;">//</span>breakwall.net<span style="color: #000000; font-weight: bold;">/</span>promo<span style="color: #000000; font-weight: bold;">/</span>install_ss.sh</pre></div></div>

<p>And press enter<br />
Then type at the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">bash</span> install_ss.sh</pre></div></div>

<p>to run the script.<br />
First the script will ask you to type a password. Then it will ask you whether to install nodejs. Press &#8216;y&#8217; for yes.<br />
After the script finishes, then all is set on the server side! So easy:-)<br />
<strong>Step Three: run the Windows client program</strong><br />
Click this link <a href="https://breakwall.net/soft/yingwa.zip">https://breakwall.net/soft/yingwa.zip</a> to download the Shadowsocks Windows client. Unzip the file and run yingwa.exe, you will get this screen:</p>
<p><img src='https://breakwall.net/wp-content/uploads/2013/03/yingwa.png' /></p>
<p>Now fill the server with your linux VPS server IP. Fill your password you have set on the server in step two. For port number type 999 .</p>
<p>And click connect. Now open IE or chrome and enjoy your work.</p>
<p>Both shadowsocks server and client are open source projects hosted at github.com</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://dallascao.com/en/the-easiest-way-to-build-your-own-vpn-server/" rel="bookmark" class="crp_title">The easiest way to build your own VPN server</a></li><li><a href="http://dallascao.com/en/run-shadowsocks-in-the-background/" rel="bookmark" class="crp_title">run shadowsocks in the background</a></li><li><a href="http://dallascao.com/en/windows-mobile-wm-opvenvpn/" rel="bookmark" class="crp_title">Install OpenVPN clients on Windows Mobile (WM) (really works!)</a></li><li><a href="http://dallascao.com/en/install-openvpn-on-ubuntu/" rel="bookmark" class="crp_title">Install openvpn on ubuntu</a></li><li><a href="http://dallascao.com/en/vps-step-by-step/" rel="bookmark" class="crp_title">Step by step LNMP installation guide for CentoOS servers</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdallascao.com%2Fen%2Fbuild-a-shadowsocks-server-an-easier-alternative-to-vpn%2F&amp;title=Build%20a%20Shadowsocks%20server%20%26%238211%3B%20an%20easier%20alternative%20to%20VPN"><img src="/en/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://dallascao.com/en/build-a-shadowsocks-server-an-easier-alternative-to-vpn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
