Date: Wed, 11 Feb 2009 13:42:14 +0200 From: Jonathan McKeown <jonathan+freebsd-questions@hst.org.za> To: freebsd-questions@freebsd.org Subject: Re: sh parameter substitution problem Message-ID: <200902111342.14584.jonathan%2Bfreebsd-questions@hst.org.za> In-Reply-To: <20090211213011.C38905@sola.nimnet.asn.au> References: <20090211213011.C38905@sola.nimnet.asn.au>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wednesday 11 February 2009 12:47:17 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'
Take out the : in the parameter expansion.
$ addr='195.68.176.4#1440:'; ip=${addr%#*}; echo $ip
195.68.176.4
: is for supplying default values or an error for unset variables.
Jonathan
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200902111342.14584.jonathan%2Bfreebsd-questions>
