for a Unix command soln you can also do:
export CUDA_VISIBLE_DEVICES=$i

though of course that only works if the scripts are independent and stuff like that…otherwise the other solutions here are probably better…