https://kotlinlang.org logo
Title
g

Gabriel Feo

02/19/2020, 9:27 AM
Anybody know how to use a bash variable in an
Exec
task’s command? Escaping the dollar sign doesn’t seem to work. For example:
commandLine = listOf("echo", "Declared in env GOOGLE_APPLICATION_CREDENTIALS=\$GOOGLE_APPLICATION_CREDENTIALS")
Output:
Declared in env GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS
o

octylFractal

02/19/2020, 9:29 AM
call bash with
-c
, rather than using exec directly
e.g.
listOf("bash", "-c", "echo 'Declared in env ...')
f

Fleshgrinder

02/19/2020, 9:31 AM
Everything inside the list you create is escaped, no matter what you do. It's equivalent to the following Bash line
'echo' 'Declared in env GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS'
and nothing gets interpreted. Do what @octylFractal said or use
System.getenv
.
☝️ 1
o

octylFractal

02/19/2020, 9:32 AM
realistically, it's not equivalent to a bash anything, it's likely doing something similar to
execve
& friends -- that means that it's not using any bash builtins such as
echo
or
cd
f

Fleshgrinder

02/19/2020, 9:37 AM
Equivalence depends on how you exactly define it. The observable side effects and logical interpretation is equivalent. 😉
o

octylFractal

02/19/2020, 9:40 AM
I suppose that depends on what you mean by "observable side effects" -- builtin echo and e.g.
/usr/bin/echo
can behave differently, but don't in most cases 😛
f

Fleshgrinder

02/19/2020, 9:45 AM
They all print something to STDOUT.
You are not wrong with your statement! Just saying that my statement for explanation is not wrong either.
g

Gabriel Feo

02/19/2020, 1:50 PM
Thank you both! :)