Unable to access local variable on remote host using sshpass. Can you please help me to pass local variable to pass on remote host using ssh pass for the below code snippet
JavaScript
x
name="Stack over flow"
sshpass -p${serverpassword} ssh -o StrictHostKeyChecking=no ${username}@${servername} 'for i in $name ; do echo $i ; done'
expected result:
JavaScript
stack
over
flow
Advertisement
Answer
Try this:
JavaScript
name="Stack over flow"
sshpass -p${serverpassword} ssh -o StrictHostKeyChecking=no ${username}@${servername}
"for i in \$name; do echo $i; done"
You need to double quote your command line and right escaping.