From owner-freebsd-questions@FreeBSD.ORG Thu Jun 24 02:20:50 2010 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 82A3E106566C for ; Thu, 24 Jun 2010 02:20:50 +0000 (UTC) (envelope-from xkyanh@gmail.com) Received: from mail-pv0-f182.google.com (mail-pv0-f182.google.com [74.125.83.182]) by mx1.freebsd.org (Postfix) with ESMTP id 5185E8FC13 for ; Thu, 24 Jun 2010 02:20:50 +0000 (UTC) Received: by pvg6 with SMTP id 6so59217pvg.13 for ; Wed, 23 Jun 2010 19:20:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:in-reply-to:references:organization:user-agent :x-operating-system:x-face:face:x-mailer:mime-version:content-type :content-transfer-encoding; bh=y8iZui+8YQ8+kOSrABWd59E4pFC04qw18/9Qq8ZObW8=; b=H6m7/TztE6Jj1JnBXfNA0vjxF2EYdwRogTfS5Y8C+kva8Lncl9vlGRSzmt4cenT6b/ a/Ns0kamtxILTv1RImsUTjzFZvfHiu2M7pQQVoD1qYw9A4ICJ9lUMFcVPW3GLeAiovdW /LrbgnexHFtXRYlVDNK09bFxdxHWrp6mGJnFw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:user-agent:x-operating-system:x-face:face:x-mailer :mime-version:content-type:content-transfer-encoding; b=wv0SoVDIJAlUs8+OJdJrXW0pvRGn20GaWBmhHUmt8LD5R9NUMlDuUN5TG619ZJj12+ 1FZf4agMIz3K3PWsD1O5zK1FbdP1KchcB0J4AkTvezfJlh4/gC1cvfOQ8uUeixb6eQ5E yOIK5RmyLCyGca/107dApjfvTn2C0aDE15+8g= Received: by 10.142.74.6 with SMTP id w6mr8261599wfa.249.1277346049796; Wed, 23 Jun 2010 19:20:49 -0700 (PDT) Received: from icy.localdomain ([115.78.0.218]) by mx.google.com with ESMTPS id e16sm4030596wfg.14.2010.06.23.19.20.47 (version=SSLv3 cipher=RC4-MD5); Wed, 23 Jun 2010 19:20:49 -0700 (PDT) Date: Thu, 24 Jun 2010 09:20:36 +0700 From: "Anh Ky Huynh" To: Aiza Message-ID: <20100624092036.6462fc1a@icy.localdomain> In-Reply-To: <4C22B3D7.6070102@comclark.com> References: <4C22B3D7.6070102@comclark.com> Organization: Vietnamese TeX Users Group User-Agent: FreeBSD X-Operating-System: FreeBSD X-Face: FreeBSD Face: FreeBSD X-Mailer: FreeBSD Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: "questions@freebsd.org" Subject: Re: .sh check for numeric content X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jun 2010 02:20:50 -0000 On Thu, 24 Jun 2010 09:24:39 +0800 Aiza wrote: > Receiving a variable from the command line that is suppose > to contain numeric values. > > How do I code a test to verify the content is numeric? echo "$your_variable" | grep -E "^[0-9]+(\.[0-9]*)*[0-9]+$" If $your_variable is numeric (123, or 123.123, etc), the return code should be 0. You can custom to script to support negative numbers. -- Anh Ky Huynh