For one thing, you are passing them as args, so in the function you cannot refer to them as $STRING and $Y - they are $1 and $2 respectively. For another, in the echo in the function you are escaping the $ on $STRING, so you are probably seeing "$STRING" anyway. And if you are passing the string and y values from the loop, you probably also want to pass the length from that context as well.
See the bash scripting guide among others for how this works.
Last edited by astrogeek; 07-28-2013 at 04:33 PM.