<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Tech-Recipes - Latest Comments in Checking if a variable is a number in ksh | Korn shell | Tech-Recipes</title><link>http://tech-recipes.disqus.com/</link><description>Cookbook of Tech Tutorials</description><language>en</language><lastBuildDate>Wed, 15 Apr 2009 15:28:07 -0000</lastBuildDate><item><title>Re: Checking if a variable is a number in ksh | Korn shell | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/756/checking-if-a-variable-is-a-number-in-ksh/#comment-8237354</link><description>I'm not sure if anyone will read this, but to check if a variable is a number in ksh, it would take 1 expression, there is no reason to add, subtract or do any arithmetic. Example of a script:&lt;br&gt;&lt;br&gt;G_VAR=$1&lt;br&gt;if [[ $G_VAR = +([0-9]) ]]; then&lt;br&gt;    print "G_VAR is a number"&lt;br&gt;else&lt;br&gt;    print "G_VAR is not a number"&lt;br&gt;fi</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Andrew</dc:creator><pubDate>Wed, 15 Apr 2009 15:28:07 -0000</pubDate></item><item><title>Re: Checking if a variable is a number in ksh | Korn shell | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/756/checking-if-a-variable-is-a-number-in-ksh/#comment-5013905</link><description>I wouldn't play with the exit status. Instead, change the arithmetic expression. Use expr $1 +1.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mr. KIPS</dc:creator><pubDate>Fri, 09 Jan 2009 12:31:11 -0000</pubDate></item><item><title>Re: Checking if a variable is a number in ksh | Korn shell | Tech-Recipes</title><link>http://www.tech-recipes.com/rx/756/checking-if-a-variable-is-a-number-in-ksh/#comment-2818404</link><description>What if $1 is 0?&lt;br&gt;You'll get FALSE!&lt;br&gt;&lt;br&gt;From expr's man page:&lt;br&gt;&lt;br&gt;    EXIT STATUS&lt;br&gt;        [...]&lt;br&gt;        0     if the expression is neither NULL nor 0&lt;br&gt;        1     if the expression is either NULL or 0&lt;br&gt;&lt;br&gt;        [...]&lt;br&gt;I'd  use "-eq 2" instead of  "-ne 0."&lt;br&gt;&lt;br&gt;Thanks anyway, good tip.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nacho_a</dc:creator><pubDate>Fri, 03 Oct 2008 04:45:49 -0000</pubDate></item></channel></rss>