In a bash script, what I need is to ssh to a server and do some commands, what I got so far is like this:
outPut=\"ss\"
ssh user@$serverAddress <
No, sorry that will not work.
Either use command substitution value (to printf) inside the here-doc (lines bettween EOF):
ssh user@$serverAddress << EOF
printf 'output is %s\n' "$(ls -l /opt/logs)"
EOF
Or you capture the execution of command from inside ssh, and then use the value.
outPut="$(
ssh user@$serverAddress << EOF
cd /opt/logs
ls -l
EOF
)"
echo 'output is ' "$outPut"
echo "${outPut}"
Option 1 looks cleaner.