ssh breaks out of while-loop in bash [duplicate]
The problem is that ssh reads from standard input, therefore it eats all your remaining lines. You can just connect its standard input to nowhere: ssh $USER@$SERVER “cd ${REMOTE_PATH}; mkdir -p $i” < /dev/null You can also use ssh -n instead of the redirection.