How can I access declared variable in bash when executing Laravel Envoy task?
Looking at the code, we can see the method being used to pass the commands. First the command is built:
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, that command is sent off to be run by PHP's proc_open
command.
Since the input is being passed via STDIN, it's getting interpreted by your local environment before being sent. You can copy and paste the above into your terminal to see the same thing.
All that's needed is to escape any characters that might be interpreted by the local environment; in this case, the $
characters.
@task('ping-ws', ['on' => 'ws'])
echo "Hello world from WS server!"
echo \$(pwd)
pwd
var_1="Hello"
echo "\${var_1}"
@endtask
Note you may need to double escape, not sure if Envoy will try to take the first escaping for itself.