buildenv.sh: fix ip retrieval logic in loop