Passing a variable to a remote host in a bash script with ssh and EOF [duplicate]
This question already has an answer here: Passing external shell script variable via ssh 2 answers I have a script parsing a list of servers, looking for some stuff and executing commands if the circumstances are correct. The main server is connecting to them via ssh, executing all commands that are in the EOF statement: #!/bin/bash # parsing servers # defining one local variable $VAR ssh -T -p 1234 root@"server-ip" "$variable" << 'EOF' # doing some stuff... var_result=$(mysql -hhost -uuser '-ppasswort' -Ddatabase -N -e "SELECT something FROM somewhere WHERE value=$VAR;") EOF I know the