Forgive the use of Elixir in this post, but I think this ends up being specific to Erlang’s open_port
Short version, when using open_port
and I set an environment variable to be an empty string, it’s not seen as different from an unset variable
Background: I was using System.shell
to run a docker build command. My Dockerfile uses RUN test -n "${NODE_OPTIONS+set}"
in order to make sure I’ve set that environment variable, however most of the time it’s empty. test -n
cares only about the width of the text, so I use +set
to populate it if it’s empty, but not unset, to help.
System.shell
is using open_port
, but adding options to the call, so I ran a test with Port.open
, which is just a rename of :erlang.open_port
. I expect the exit statuses below to be 1, 0, 0
iex(1)> port = Port.open({:spawn, ~c[test -n "${NODE_OPTIONS+set}"]}, [:exit_status, env: []])
#Port<0.3>
iex(2)> port = Port.open({:spawn, ~c[test -n "${NODE_OPTIONS+set}"]}, [:exit_status, env: [{~c"NODE_OPTIONS", ~c" "}]])
#Port<0.4>
iex(3)> port = Port.open({:spawn, ~c[test -n "${NODE_OPTIONS+set}"]}, [:exit_status, env: [{~c"NODE_OPTIONS", ~c""}]])
#Port<0.5>
iex(4)> flush()
{#Port<0.3>, {:exit_status, 1}}
{#Port<0.4>, {:exit_status, 0}}
{#Port<0.5>, {:exit_status, 1}}
:ok
Is this a bug, or have I missed something?
This is erlang 26.2.5.2