I'm trying to ssh into a remote host, load an environment variable in the .zshrc
file on the host, then execute a command using that environment variable.
Here's my script so far,
#!/usr/bin/expect -fspawn ssh hostnamesend "echo $my_variable\n"interact
and the .zshrc
file on my remote host has these contents,
export my_variable=banana_tree
I get this output when running my script above,
spawn ssh hostnamecan't read "my_variable": no such variable while executing"send "echo $my_variable\n"" (file "/Users/me/myscript.sh" line 6)
I know the error message is saying expect can't find the variable because it's not defined in the environment where I'm executing the script, and one workaround is to define the variable where I'm running the script, however I'd prefer to keep the variable defined on the remote host only if possible.