Surely it's not necessary to put double quotes around $? ...that can only have an integral value, no?
regards, tom lane