Even if it's been some time, I'll answer my question with the solution I used for my problem.
After struggling a LOT with the combination of heredocs and SSH, I came up with a partial solution :
MY_ARRAY=('value1' 'value2' 'value3' 'wrongValue)
ssh admin@machine -T << EOF >output.file
for VALUE in "${MY_ARRAY[@]}"
do
if [[ \$VALUE =~ ^v ]] ; then
echo "\$VALUE : \$(matching_function \$VALUE)"
else
echo "\$VALUE : this is a wrong value"
fi
done
EOF
I used $
before local variables, and \$
before remote ones. This is due to heredoc behaviour, as bash
interpretes every varaible preceeded by a $
before executing the content of the heredoc.
The >output.file
allowed me to catch the output of the ssh command and do some postprocessing. However, I never found out how to allocate a variable out of the <<EOF ... EOF
, but I guess this is more of a heredoc issue.
I'll accept my answer as of now, but I'll be glad if anyone could clarify why/if it is impossible to allocate a variable from the heredoc to the outside.