<?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: Testing AlphaNumeric Arguments In Bash</title>
	<atom:link href="http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/</link>
	<description>Linux.  GNU.  Freedom.</description>
	<lastBuildDate>Wed, 16 May 2012 07:36:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-beta2-20489</generator>
	<item>
		<title>By: Krayon</title>
		<link>http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-110147</link>
		<dc:creator>Krayon</dc:creator>
		<pubDate>Thu, 10 Sep 2009 06:52:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-110147</guid>
		<description>If you&#039;re just interested in validating the input, you can just something like:
  input=&quot;$(echo $input&#124;sed &#039;/[^[:alphanum:]]/d&#039;
  if [ &quot;$input&quot; == &quot;&quot; ]; then
    echo &quot;Invalid input&quot;
  fi

The advantage of this is that it&#039;ll set it to &quot;&quot; if there&#039;s even 1 incorrect character.  In theory entering anything other than the expected could imply the user doesn&#039;t know what they are entering :P</description>
		<content:encoded><![CDATA[<p>If you&#8217;re just interested in validating the input, you can just something like:<br />
  input=&#8221;$(echo $input|sed &#8216;/[^[:alphanum:]]/d&#8217;<br />
  if [ "$input" == "" ]; then<br />
    echo &#8220;Invalid input&#8221;<br />
  fi</p>
<p>The advantage of this is that it&#8217;ll set it to &#8220;&#8221; if there&#8217;s even 1 incorrect character.  In theory entering anything other than the expected could imply the user doesn&#8217;t know what they are entering <img src='http://pthree.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan Rome</title>
		<link>http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-109998</link>
		<dc:creator>Jan Rome</dc:creator>
		<pubDate>Thu, 21 May 2009 11:12:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-109998</guid>
		<description>I also agree that Aarons version is better because it is more flexible:

validate_input() {
 INPUT=&quot;$(echo $1 &#124; sed -e &#039;s/_//g&#039;)&quot;
 VALID=&quot;$(echo $INPUT &#124; sed -e &#039;s/[^[:alnum:]]//g&#039;)&quot;
 if [ &quot;$INPUT&quot; != &quot;$VALID&quot; ]; then
    echo &quot;string contains invalid characters&quot;
 fi
} 

Based on Aarons code, we can make a slight modification of the INPUT variables value. Basically, it allows a user to match only alpha numeric input, but with inclusion of the $(echo $1 &#124; sed -e &#039;s/_//g&#039;) part, we can make exceptions to the [^[:alnum:]] part.

The final result is such that the function will allow only alpha numeric input and characters specified in the INPUT variables sed part.

Broken down:
1) invoke the function:    validate_input 
2) use sed to remove the underscore from blah_blah and set the result as the variable INPUT
3) use sed to restrict the VALID variable to alphanumeric characters
4) compare the two, if they differ, report that there are invalid characters present.

One can thus restrict the valid input to only alphanumeric characters and other user specified characters... (in our case, the underscore)</description>
		<content:encoded><![CDATA[<p>I also agree that Aarons version is better because it is more flexible:</p>
<p>validate_input() {<br />
 INPUT=&#8221;$(echo $1 | sed -e &#8216;s/_//g&#8217;)&#8221;<br />
 VALID=&#8221;$(echo $INPUT | sed -e &#8216;s/[^[:alnum:]]//g&#8217;)&#8221;<br />
 if [ "$INPUT" != "$VALID" ]; then<br />
    echo &#8220;string contains invalid characters&#8221;<br />
 fi<br />
} </p>
<p>Based on Aarons code, we can make a slight modification of the INPUT variables value. Basically, it allows a user to match only alpha numeric input, but with inclusion of the $(echo $1 | sed -e &#8216;s/_//g&#8217;) part, we can make exceptions to the [^[:alnum:]] part.</p>
<p>The final result is such that the function will allow only alpha numeric input and characters specified in the INPUT variables sed part.</p>
<p>Broken down:<br />
1) invoke the function:    validate_input<br />
2) use sed to remove the underscore from blah_blah and set the result as the variable INPUT<br />
3) use sed to restrict the VALID variable to alphanumeric characters<br />
4) compare the two, if they differ, report that there are invalid characters present.</p>
<p>One can thus restrict the valid input to only alphanumeric characters and other user specified characters&#8230; (in our case, the underscore)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gareth Williams</title>
		<link>http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-100392</link>
		<dc:creator>Gareth Williams</dc:creator>
		<pubDate>Mon, 12 May 2008 13:11:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-100392</guid>
		<description>Very useful discussion - taught me a few things as a beginner:
1) don&#039;t cut and paste the examples from the comments into a script as they won&#039;t work - the quote marks need to be typed as proper single or double quotes!
2) the &quot;\W&quot; example works differently from the other two as it will allow underscore in the input text.
:-)</description>
		<content:encoded><![CDATA[<p>Very useful discussion &#8211; taught me a few things as a beginner:<br />
1) don&#8217;t cut and paste the examples from the comments into a script as they won&#8217;t work &#8211; the quote marks need to be typed as proper single or double quotes!<br />
2) the &#8220;\W&#8221; example works differently from the other two as it will allow underscore in the input text.<br />
 <img src='http://pthree.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron</title>
		<link>http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-87861</link>
		<dc:creator>Aaron</dc:creator>
		<pubDate>Fri, 04 Jan 2008 14:36:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-87861</guid>
		<description>@David Tomaschik and Tormod Volden- The idea isn&#039;t simplicity, but elegance and flexibility.  Dave Taylor&#039;s solution brings more to the table, and let&#039;s the script writer take advantage of the $compressed variable if needed.

@Dave Taylor-  Welcome!  I was worried that the code may be copyrighted or otherwise unavailable for redistribution.  So, as you may have noticed, I changed the script considerably &quot;just in case&quot;. :)  Anyway, it&#039;s a great book, and I&#039;m looking forward to learning more from it.</description>
		<content:encoded><![CDATA[<p>@David Tomaschik and Tormod Volden- The idea isn&#8217;t simplicity, but elegance and flexibility.  Dave Taylor&#8217;s solution brings more to the table, and let&#8217;s the script writer take advantage of the $compressed variable if needed.</p>
<p>@Dave Taylor-  Welcome!  I was worried that the code may be copyrighted or otherwise unavailable for redistribution.  So, as you may have noticed, I changed the script considerably &#8220;just in case&#8221;. <img src='http://pthree.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Anyway, it&#8217;s a great book, and I&#8217;m looking forward to learning more from it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Taylor</title>
		<link>http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-87858</link>
		<dc:creator>Dave Taylor</dc:creator>
		<pubDate>Fri, 04 Jan 2008 13:44:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-87858</guid>
		<description>How can I be upset when you refer to my script as &quot;elegant and clean&quot;? :-)  Seriously, I love to see people further hack and push the bits around. Trust me, I&#039;m not the world&#039;s best shell script writer, I just have persistence. :-)</description>
		<content:encoded><![CDATA[<p>How can I be upset when you refer to my script as &#8220;elegant and clean&#8221;? <img src='http://pthree.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Seriously, I love to see people further hack and push the bits around. Trust me, I&#8217;m not the world&#8217;s best shell script writer, I just have persistence. <img src='http://pthree.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tormod Volden</title>
		<link>http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-87854</link>
		<dc:creator>Tormod Volden</dc:creator>
		<pubDate>Fri, 04 Jan 2008 12:51:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-87854</guid>
		<description>Or better:
if echo $input &#124; egrep -q &quot;\W&quot;</description>
		<content:encoded><![CDATA[<p>Or better:<br />
if echo $input | egrep -q &#8220;\W&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Tomaschik</title>
		<link>http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-87825</link>
		<dc:creator>David Tomaschik</dc:creator>
		<pubDate>Fri, 04 Jan 2008 05:24:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comment-87825</guid>
		<description>I think this might be simpler:

if echo $input &#124; grep -q &#039;[^0-9A-Za-z]&#039;
    then echo &quot;Input not valid.&quot;
else
    echo &quot;Input valid.&quot;
fi</description>
		<content:encoded><![CDATA[<p>I think this might be simpler:</p>
<p>if echo $input | grep -q &#8216;[^0-9A-Za-z]&#8216;<br />
    then echo &#8220;Input not valid.&#8221;<br />
else<br />
    echo &#8220;Input valid.&#8221;<br />
fi</p>
]]></content:encoded>
	</item>
</channel>
</rss>

