Passing variables in remote ssh command

前端 未结 7 1698
余生分开走
余生分开走 2020-12-04 11:59

I want to be able to run a command from my machine using ssh and pass through the environment variable $BUILD_NUMBER

Here\'s what I\'m trying:



        
7条回答
  •  青春惊慌失措
    2020-12-04 12:14

    As answered previously, you do not need to set the environment variable on the remote host. Instead, you can simply do the meta-expansion on the local host, and pass the value to the remote host.

    ssh pvt@192.168.1.133 '~/tools/run_pvt.pl $BUILD_NUMBER'
    

    If you really want to set the environment variable on the remote host and use it, you can use the env program

    ssh pvt@192.168.1.133 "env BUILD_NUMBER=$BUILD_NUMBER ~/tools/run_pvt.pl \$BUILD_NUMBER"
    

    In this case this is a bit of an overkill, and note

    • env BUILD_NUMBER=$BUILD_NUMBER does the meta expansion on the local host
    • the remote BUILD_NUMBER environment variable will be used by
      the remote shell

提交回复
热议问题