How can I access a declared variable in bash while doing a Larvel Envoy job?

I have a simple Envoy setup. Server:

@servers(['ws' => 'ws.sk']) 

... and the simple ping task:

 @task('ping-ws', ['on' => 'ws']) echo "Hello world from WS server!" echo $(pwd) pwd var_1="Hello" echo "${var_1}" @endtask 

Where I would like to assign some values ​​to variables and access them later. Although the result is quite unexpected:

 envoy run ping-ws Hello world from WS server! /Users/davidlukac/dev/drupal/_devdesktop/davidlukac /home 
  • The $(pwd) is evaluated locally.
  • var_1 either var_1 or out of scope in the next line.

Is this the expected behavior? Is there a workaround?

Thanks for the help!

+5
source share
1 answer

Looking at the code , we can see the method used to transmit commands. First, the command is created:

 ssh ws.sk 'bash -se' << EOF-LARAVEL-ENVOY echo "Hello world from WS server!" echo $(pwd) pwd var_1="Hello" echo "${var_1}" EOF-LARAVEL-ENVOY 

And then , this command is sent to run PHP proc_open .

Since the input is transmitted via STDIN, it receives an interpretation by your local environment before sending. You can copy and paste the above into your terminal to see the same.

All that is needed is to avoid any characters that can be interpreted by the local environment; in this case, the characters are $ .

 @task('ping-ws', ['on' => 'ws']) echo "Hello world from WS server!" echo \$(pwd) pwd var_1="Hello" echo "\${var_1}" @endtask 

Please note that you may need to double the flight, not sure if Envoy will try the first screening for itself.

+1
source

Source: https://habr.com/ru/post/1245167/


All Articles