> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] 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. [EMAIL PROTECTED]" 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 _______________________________________________ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"