<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>JustLinux Forums - Programming/Scripts</title>
		<link>http://forums.justlinux.com/</link>
		<description>Perl, Python, C/C++, Java, CGI, shell, etc. Share your code!</description>
		<language>en</language>
		<lastBuildDate>Sat, 25 May 2013 13:57:53 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://forums.justlinux.com/images/misc/rss.png</url>
			<title>JustLinux Forums - Programming/Scripts</title>
			<link>http://forums.justlinux.com/</link>
		</image>
		<item>
			<title>bash regex</title>
			<link>http://forums.justlinux.com/showthread.php?154443-bash-regex&amp;goto=newpost</link>
			<pubDate>Tue, 21 May 2013 22:16:03 GMT</pubDate>
			<description>I am trying to make sure that the number entered for the barcode variable is exactly 10 digits long but it doesnt work and get the following error.  What am I doing wrong? 
 
error: ./regex.sh: line...</description>
			<content:encoded><![CDATA[<div>I am trying to make sure that the number entered for the barcode variable is exactly 10 digits long but it doesnt work and get the following error.  What am I doing wrong?<br />
<br />
error: ./regex.sh: line 6: [: =~: binary operator expected<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">if [ ${barcode} =~ &quot;[0-9]{10}&quot; ]<br />
then<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;Regex Passes!&quot;<br />
else<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;Regex Failed!&quot;<br />
fi</code><hr />
</div> If I change the =~ to == I don't get an error but it still fails when it shouldnt, I assume thats because I am then comparing 2 different numbers for equality, rather than testing for an acceptable pattern.<br />
<br />
I did get the following to work but it wasn't what I was going for.. also it allows numbers longer than 10 digits to be accepted.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">if echo ${barcode} | grep -Eq '[0-9]{10}'<br />
then<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;Regex Passes!&quot;<br />
else<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;Regex Failed!&quot;<br />
fi</code><hr />
</div> </div>

 ]]></content:encoded>
			<category domain="http://forums.justlinux.com/forumdisplay.php?28-Programming-Scripts">Programming/Scripts</category>
			<dc:creator>jiggolo182</dc:creator>
			<guid isPermaLink="true">http://forums.justlinux.com/showthread.php?154443-bash-regex</guid>
		</item>
	</channel>
</rss>
