From owner-freebsd-questions@FreeBSD.ORG Sat Aug 18 17:30:48 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A295816A477 for ; Sat, 18 Aug 2007 17:30:48 +0000 (UTC) (envelope-from mail@chdevelopment.se) Received: from av7-1-sn3.vrr.skanova.net (av7-1-sn3.vrr.skanova.net [81.228.9.181]) by mx1.freebsd.org (Postfix) with ESMTP id 4388F13C45E for ; Sat, 18 Aug 2007 17:30:47 +0000 (UTC) (envelope-from mail@chdevelopment.se) Received: by av7-1-sn3.vrr.skanova.net (Postfix, from userid 502) id CEC8B38497; Sat, 18 Aug 2007 19:03:42 +0200 (CEST) Received: from smtp3-2-sn3.vrr.skanova.net (smtp3-2-sn3.vrr.skanova.net [81.228.9.102]) by av7-1-sn3.vrr.skanova.net (Postfix) with ESMTP id 8BA2F37E77 for ; Sat, 18 Aug 2007 19:03:42 +0200 (CEST) Received: from melissa.chdevelopment.se (90-227-26-163-no68.tbcn.telia.com [90.227.26.163]) by smtp3-2-sn3.vrr.skanova.net (Postfix) with ESMTP id 29DD137E4B for ; Sat, 18 Aug 2007 19:04:40 +0200 (CEST) Message-ID: <46C726A8.9010404@chdevelopment.se> Date: Sat, 18 Aug 2007 19:04:40 +0200 From: Christer Hermansson User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.8.1.6) Gecko/20070811 SeaMonkey/1.1.4 MIME-Version: 1.0 To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Regular expressions 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: Sat, 18 Aug 2007 17:30:48 -0000 Hi. I'm trying to use regular expressions inside a shell script (/bin/sh) on my freebsd box and can't get it to work so I searched the web and found http://regexlib.com/RETester.aspx On this webpage I could test my pattern "^[A-Za-z0-9_-]+$" and everything was fine, did exactly what I wanted to do, check that a string only contains some combination of the characters A-Z, a-z, 0-9, hyphen - and underscore _. I also found some basic example at http://www.grymoire.com/Unix/Sh.html#uh-88 : --------8<--------8<--------8<--------8<--------8<-------- #!/bin/sh echo "Type in a number" read ans number=`expr "$ans" : "([0-9]*)"` if [ "$number" != "$ans" ]; then echo "Not a number" elif [ "$number" -eq 0 ]; then echo "Nothing was typed" else echo "$number is a fine number" fi --------8<--------8<--------8<--------8<--------8<-------- The above example doesn't work on my freebsd box. Maybe I need to update my system, sitting with 6.0R which never been updated. Is there anyone who has some advice about how to get regular expressions to work in FreeBSD shell script ? -- Christer Hermansson