From owner-freebsd-questions@FreeBSD.ORG Fri Sep 5 16:38:30 2008 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 C3B9B106569A for ; Fri, 5 Sep 2008 16:38:30 +0000 (UTC) (envelope-from bounces@nabble.com) Received: from kuber.nabble.com (kuber.nabble.com [216.139.236.158]) by mx1.freebsd.org (Postfix) with ESMTP id 9AFCB8FC1D for ; Fri, 5 Sep 2008 16:38:30 +0000 (UTC) (envelope-from bounces@nabble.com) Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1KbeKL-0007G6-MJ for freebsd-questions@freebsd.org; Fri, 05 Sep 2008 09:38:29 -0700 Message-ID: <19335104.post@talk.nabble.com> Date: Fri, 5 Sep 2008 09:38:29 -0700 (PDT) From: Jim Hertzler To: freebsd-questions@freebsd.org In-Reply-To: <499449.17617.qm@web57002.mail.re3.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: jimhertzler@ntelos.net References: <499449.17617.qm@web57002.mail.re3.yahoo.com> Subject: Re: string split, bash and IFS 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: Fri, 05 Sep 2008 16:38:30 -0000 #!/bin/bash # Split the command line argument on the colon character. SaveIFS=$IFS IFS=":" declare -a Array=($*) IFS=SaveIFS echo "Array[0]=${Array[0]}" echo "Array[1]=${Array[1]}" echo "Array[2]=${Array[2]}" echo "Array[3]=${Array[3]}" Unga wrote: > > Hi all > > How to use bash and IFS to split a string? > > eg. > $string = "Name:Surname:10" > IFS=: > echo "$string" | read name surname age > > This does not work for some reason. The read does not create name, surname > and age variables. Any idea why? > > Appreciate your reply. > > Kind regards > Unga > > > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org" > > -- View this message in context: http://www.nabble.com/string-split%2C-bash-and-IFS-tp19140697p19335104.html Sent from the freebsd-questions mailing list archive at Nabble.com.