Many systems have AcceptEnv LC_*
in their sshd
configuration, so you can do:
export LC_DIR="$varWheelsDir"
shell_code='
pip3 install --force-reinstall --user "$LC_DIR"/bbw*
'
eval "$shell_code" # interpreted by current shell
ssh -e SendEnv=LC_DIR -t admin@otherhost "$shell_code"
interpreted by the login shell of admin on otherhost,
assuming it is Bourne-like
With the same shell code run locally and remotely, and sharing a $LC_DIR
variable with the same contents.
Alternatively, if the local shell is zsh and you know the login shell of admin
on otherhost
is Bourne-like, you can construct the shell code where the contents of the local $varWheelsDir
variable is embedded and quoted in a safe way with:
pip3 install --force-reinstall --user "${varWheelsDir}"/bbw* # local
ssh -t admin@otherhost "
pip3 install --force-reinstall --user ${(qq)varWheelsDir}/bbw"* # remote
Where ${(qq)var}
quotes the contents of $var
in sh syntax using single quotes (the safest form of quoting for arbitrary data).
Recent versions of bash
have a ${var@Q}
operator to expanded $var
, quoted, but it produces non-portable bash-specific syntax in some circumstances, and not only using single quotes, so you can only use it if the login shell of admin
on otherhost
happens to be bash
(preferably of the same version and running in the same locale).
If you can't guarantee the login shell of admin
on otherhost
is Bourne-like, see How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user? for possible approaches.
$
before*
on the remote command? Simplyssh -t admin@otherhost "pip3 install --user '${varWheelsDir}/bbw'*"
should work. – Paul Pazderski Aug 01 '23 at 11:26