Despite my searches, I can't find what's wrong.
Locally :
RESULT="dir 1
dir 2"
IFS=$'\n'
for R in $RESULT ; do
echo "$R"
done
is ok
Remotely :
RESULT="dir 1
dir 2"
ssh -x -T ${HOST}<<-EOF
IFS=$'\n'
for R in $RESULT ; do
echo "\$R"
done
EOF
gives error:
-bash: line 4: syntax error near unexpected token `dir'
-bash: line 4: `dir 2 ; do'
My need is obviously not that simple, but it seems to me that this is the simplest example that corresponds to it.
Edit: Thanks for the answers, but I can't get the desired result with declare -p RESULT, even after consulting all the links indicated
$ for i in ${RESULT[@]} ; do echo "$i" ; done
dir 1
dir 2
$ ssh -x -T ${POSTE_DEST}<<-EOF
$(declare -p RESULT)
for R in ${RESULT[@]} ; do
echo "\$R"
done
EOF
dir
1
dir
2
Maybe you could give me a real answer that works?
For @Barmar:
ssh -x -T ${POSTE_DEST}<<-EOF
> $(declare -p RESULT)
> for R in "${RESULT[@]}" ; do
> echo "\$R"
> done
> EOF
dir 1 dir 2