[erlang-questions] Re: how do I get the actual list of arguments passed to an escript?

Matthias Lang matthias@REDACTED
Mon Apr 4 17:27:34 CEST 2011


Problem solved. 

TLDR: I outsmarted myself with a collection of symlinks and a broken
      shell script.

Long version: here's what was happening

  1. escript is a C program (part of the Erlang/OTP distribution)

  2. escript shuffles arguments around and then actually runs 'erl',
     after figuring out which 'erl' to run.

     Unless you have the environment variable ESCRIPT_EMULATOR set,
     which you normally don't, then 'escript' tries to run 'erl'
     in the same directory as 'escript'.

     If 'escript' is a symlink, which it normally isn't, but is in my case,
     then the answer is a bare 'erl', i.e. "whatever's in the path".

  3. The first 'erl' in my path is a shell script to an older Erlang:

        #!
        /usr/local/src/otp_src_R14B01/bin/erl $@

     That's probably a left-over from some debugging effort.

  4. The $@ variable in BASH is subject to "word splitting", but that
     can be disabled by writing "$@", which is equivalent to "$1" "$2" "$3" ...

It feels like #3 and #4 ganged up to trick me... Without having thought
it through much, I can't see why $@ doesn't always behave like "$@"
(why would you want to word expand all arguments? By default?!).

I thought about how to improve escript so that it doesn't end up running
the wrong Erlang in situations like mine. I had two ideas:

  - The escript functionality could be rolled into 'erl', i.e. by having
    the 'erl' shell script do different things deending on the value of $0,
    like busybox or hd/hexdump.

    But that won't work on Windows (not that I care...) and involves
    writing more shell scripts which I tend to screw up.

  - escript.c could check if progname is a symlink and follow that
    link, recursively.

    That feels like a better idea. Or is there a gotcha?

Thanks to "Harsh J" for putting me on the right track by showing that
this problem is specific to my setup. And, just before posting this,
I see that Steve Vinoski figured out #3 without even seeing my setup.

Matt



More information about the erlang-questions mailing list