Fix bugs in link.sh