Context
I have a script that iterates over a list. At each iteration it is expected to invoke a function that constructs a 'diff' command for comparing two remote files via 'eval'.
The 'diff' command gets its inputs through two process substitutions where each one cats a remote file via 'ssh' that performs a passwordless authentication (through public/private keys).
The 'diff' and 'ssh' executions have been tested out of the script and they work fine.
Code
Here I post a very short version of my script which however produces the same problem:
#!/bin/bash
func(){
NUM=$1
echo "func $NUM"
COMMAND="diff <(ssh user1@server1 'cat file1' ) <(ssh user2@server2 'cat file2' )"
eval "${COMMAND}" 1>/dev/null
RESULT=$?
}
LIST="1
2
3
4
5"
echo "$LIST" | while read NUM ; do
echo "main $NUM"
func $NUM
done
Expected result
main 1
func 1
main 2
func 2
main 3
func 3
main 4
func 4
main 5
func 5
Problem
The script stops after the first iteration:
main 1
func 1
Question
Do you know why the loop stops? and how to solve it?