in bin/sh need to split a vaiable on '_'.

December 8, 2010 at 16:30:12
Specs: UNIX
in bin/sh script a variable passed contains data like xxxx_yyyyyy. I want to keep that variable and populate 2 other variables defined in the script, each containing the data on either side of the underscore.

See More: in bin/sh need to split a vaiable on _.

Report •

#1
December 8, 2010 at 23:09:57
When parsing the "str" variable, make sure that you have saved arguments $1 and $2 before executing the set command:

#!/bin/sh

str="xxxx_yyyyyy"
set - `IFS="_"; echo ${str}`
varx=$1
vary=$2

echo "$varx"
echo "$vary"


Report •

#2
December 9, 2010 at 08:58:46
Thanks for the code Nails. It did the trick.

Report •
Related Solutions


Ask Question