I'm trying to execute some commands on remote host like this :ssh -t -t -l user 172.20.20.20 <<EOF  pid=$(ps -ef | grep [a]pp-management | awk '{print $2}') && kill -9 $pid && rm -rf CI/*EOFWhat happens is that I remain logged at remote server and the kill is not executed :user@ubuntu:~$ pid= && kill -9  && rm -rf CI/*kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]Neither rm gets executed, what am I doing wrong? I see that nothing get passed to kill -9 command, why is this?
Execute command on remote host fails
shell;shell script;ssh;here document
The expansions introduced by $ signs in the heredoc are evaluated locally, before generating the string that is passed as input to the ssh command.To avoid this, escape the commands in your heredoc, for instance with quotes around EOFssh ... <<EOF