Anybody know how to use a bash variable in an `Exe...
# gradle
g
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:
Copy code
commandLine = listOf("echo", "Declared in env GOOGLE_APPLICATION_CREDENTIALS=\$GOOGLE_APPLICATION_CREDENTIALS")
Output:
Copy code
Declared in env GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS
o
call bash with
-c
, rather than using exec directly
e.g.
listOf("bash", "-c", "echo 'Declared in env ...')
f
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
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
Equivalence depends on how you exactly define it. The observable side effects and logical interpretation is equivalent. 😉
o
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
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
Thank you both! :)