I have written a sample KornShell function to split a String, put it in an array and then print out the values. The code is as below
#!/usr/bin/ksh
splitString() {
string="abc@hotmail.com;xyz@gmail.com;uvw@yahoo.com"
oIFS="$IFS";
IFS=';'
set -A str $string
IFS="$oIFS"
}
splitString
echo "strings count = ${#str[@]}"
echo "first : ${str[0]}";
echo "second: ${str[1]}";
echo "third : ${str[2]}";
Now the echo does not print out the values of the array, so I assume it has something to do with the scope of the array defined.
I am new to Shell scripting, can anybody help me out with understanding the scope of variables in the example above?