From owner-freebsd-questions@FreeBSD.ORG Mon Aug 25 11:54:34 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 8AE1B1065694 for ; Mon, 25 Aug 2008 11:54:34 +0000 (UTC) (envelope-from barry.byrne@wbtsystems.com) Received: from hermes.wbtsystems.com (hermes.wbtsystems.com [193.120.231.28]) by mx1.freebsd.org (Postfix) with ESMTP id 5D9748FC1C for ; Mon, 25 Aug 2008 11:54:34 +0000 (UTC) (envelope-from barry.byrne@wbtsystems.com) Received: from SUNYA (sunya.wbt.wbtsystems.com [10.12.1.114]) by hermes.wbtsystems.com (Postfix) with ESMTPA id 05D7FF741F; Mon, 25 Aug 2008 12:54:32 +0100 (IST) From: "Barry Byrne" To: , References: <499449.17617.qm@web57002.mail.re3.yahoo.com> Date: Mon, 25 Aug 2008 12:54:35 +0100 Message-ID: <01c301c906a9$57f7d830$72010c0a@wbt.wbtsystems.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: AckGlpFWSsNSgIBLS1OgVqhD7uxJiQAEb8rg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350 In-Reply-To: <499449.17617.qm@web57002.mail.re3.yahoo.com> Cc: 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: Mon, 25 Aug 2008 11:54:34 -0000 > -----Original Message----- > From: owner-freebsd-questions@freebsd.org > [mailto:owner-freebsd-questions@freebsd.org] On Behalf Of Unga > Sent: 25 August 2008 10:40 > To: freebsd-questions@freebsd.org > Subject: string split, bash and IFS > 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. d-questions-unsubscribe@freebsd.org" Unga: I think your problem is that each element of the pipeline runs in a separate process, so has no access to the variables from other processes. You could try something like: echo "Name:Surname:10" | ( IFS=: ; read name surname age ; echo $surname) Also, probably a typo - but you're assignment of string in the first line should omit the $ sign. - barry