Skip to content

Instantly share code, notes, and snippets.

@robertoaloi
Created August 31, 2011 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertoaloi/1184144 to your computer and use it in GitHub Desktop.
Save robertoaloi/1184144 to your computer and use it in GitHub Desktop.
Weird behaviour when calling Erlang from a Makefile on Mac
#!/bin/sh
CMD="erl -noinput -eval 'erlang:display({foo, bar}).' -s init stop"
echo "Exec: $CMD"
exec $CMD
@robertoaloi
Copy link
Author

Revision #39603b will output the following error:

(no error logger present) error: "Error in process <0.0.0> with exit value: {function_clause,[{init,prepare_run_args,[{eval,[<<21 bytes>>,<<7 bytes>>]}]},{init,map,2},{init,boot,1}]}\n"

@richcarl
Copy link

The printout is mangled: [>,>] cannot be the real Erlang term here. I think that something causes the argument to -init to be expanded to two separate words by the Mac shell. For example, this reproduces the error on my Linux laptop:

erl -noinput -eval one two -s init stop
(no error logger present) error: "Error in process <0.0.0> with exit value: {function_clause [{init,prepare_run_args,[{eval,[<<3 bytes>>,<<3 bytes>>]}]},{init,map,2},{init,boot,1}]}

(You can see in the Mac printout that the <0.0.0> is also missing - there's two spaces between "process" and "with".)

@robertoaloi
Copy link
Author

The output has been modified when copying it in the gist. It looks all right in the shell.

@richcarl
Copy link

richcarl commented Sep 1, 2011

The same thing happened to my comment above (updated now). I had forgotten to markdownify it properly.

Anyway, shell expansion is the problem. The same happens on Linux. When you wrap the CMD text in double quotes, you apparently prevent the single quotes from being considered as quotes in the $CMD expansion, so you effectively get the following:

exec "erl"  "-noinput"  "-eval"  "'erlang:display({foo,"  "bar}).'"  "-s"  "init"  "stop"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment