【问题标题】:Access remote machine's exported variable via ssh通过 ssh 访问远程机器的导出变量
【发布时间】:2016-11-10 11:30:54
【问题描述】:

所以,我正在尝试的是:

  • 192.168.1.2机器中,我在.bash_profile文件www用户中设置了export name=arun
  • 然后执行source .bash_profile
  • 来自192.168.1.3 机器,我正在尝试ssh www@192.168.1.2 "echo $name"

这让我空白。这不应该回我arun吗?

【问题讨论】:

    标签: linux shell ssh


    【解决方案1】:

    没有。您需要转义要在远程 shell 上评估的变量,而不是在本地:

    ssh www@192.168.1.2 ". .bash_profile;echo \$name"
    

    【讨论】:

    • 即使这是返回空白。
    • 然后确保 bash_profile 的来源:source .bash_profile
    • 这很好用!那么,我们需要为我可能运行的每个此类命令获取 .bash_profile 吗?有没有办法在 192.168.1.2 上获取一次并从 ssh 多次使用变量?
    • 可能是的。 Bash 配置文件仅用于交互式登录。
    • 酷。谢谢 :)。标记为解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多