ssh running on function

i have a problem regarding running an ssh command while inside "function"

script structure

#!/usr/bin/bash

func1(){
          script=$1
          ssh user@server "$script"
}

cat script.txt | while read line
do
          func1 $line
done
exit 0

the problem is when ssh ran, the "while read line" seems to just read the first line of the file and proceed with "exit 0"

but its working well when ssh was replace with some other command like "echo"

the remotely executed script doesnt contain "exit" command, so no way the remote script will end the parent script.

anyone has an idea?

Hi.

I'm not sure, but I think ssh closes stdin once it finishes (??) - that's certainly the symptom.

exec 3< script.txt
while read line <&3
do
          func1 $line
done
exit 0