From owner-freebsd-questions@FreeBSD.ORG Wed Feb 11 11:36:40 2009 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 B5CD61065678 for ; Wed, 11 Feb 2009 11:36:40 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 0F5578FC0A for ; Wed, 11 Feb 2009 11:36:39 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (ppp160-57.adsl.forthnet.gr [194.219.40.57]) (authenticated bits=128) by igloo.linux.gr (8.14.3/8.14.3/Debian-5) with ESMTP id n1BBML9m028560 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 11 Feb 2009 13:22:28 +0200 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id n1BBMLI1014976; Wed, 11 Feb 2009 13:22:21 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id n1BBMKc3014975; Wed, 11 Feb 2009 13:22:20 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: Ian Smith References: <20090211213011.C38905@sola.nimnet.asn.au> Date: Wed, 11 Feb 2009 13:22:20 +0200 In-Reply-To: <20090211213011.C38905@sola.nimnet.asn.au> (Ian Smith's message of "Wed, 11 Feb 2009 21:47:17 +1100 (EST)") Message-ID: <87ljsdusk3.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-MailScanner-ID: n1BBML9m028560 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-2.342, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL -0.54) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: questions@freebsd.org Subject: Re: sh parameter substitution problem 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: Wed, 11 Feb 2009 11:36:41 -0000 On Wed, 11 Feb 2009 21:47:17 +1100 (EST), Ian Smith wrote: > I'm getting nowhere trying to parse out IP addresses from strings of > this form in /bin/sh, which have been awk'd out of 'tail named.run': > > addr='195.68.176.4#1440:' > addr='195.68.176.4#16811:' > addr='195.68.176.4#276:' > > sh(1) in hand, I've tried: > > ip=${addr:%#*} > ip=${addr:%%#*} > ip=${addr:%[#]*} > ip=${addr:%%[#]*} > > but all of these report './testbit: 7: Syntax error: Bad substitution' > > How can I split these strings to exclude the '#' and all beyond, > preferably using sh syntax, at least without resorting to perl? Remove the ':' part and quote the text to avoid parsing '#' as a comment delimiter: $ addr='195.68.176.4#1440:' $ echo "${addr%#*}" 195.68.176.4