Date: Mon, 25 Aug 2008 12:54:35 +0100 From: "Barry Byrne" <barry.byrne@wbtsystems.com> To: <unga888@yahoo.com>, <freebsd-questions@freebsd.org> Subject: RE: string split, bash and IFS Message-ID: <01c301c906a9$57f7d830$72010c0a@wbt.wbtsystems.com> In-Reply-To: <499449.17617.qm@web57002.mail.re3.yahoo.com> References: <499449.17617.qm@web57002.mail.re3.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> -----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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?01c301c906a9$57f7d830$72010c0a>