redirect variable to same program at next loop

Hi all,

I don't know how to redirect a variable in this case:

while true
do
./ready_data
...
done

ready_data should read a file looking for an ID, if this doesn't exist then add the last ID seen into the first line.

When ID exists there is no problem, but when ID doesn't exist, I need the ID variable (inside ready_data) for the next loop process. I have tried with global variables but it seems not working.

while true
do
ID=`./ready_data` with echo ID inside ready_data is not working
done

Any idea on how can I do it?

Thanks