escript, flags to script

Luke Gorrie luke@REDACTED
Fri Mar 23 16:31:33 CET 2001


Bengt Kleberg <qtxkleb@REDACTED> writes:

> Greetings,
> 
> How do I get escript to recognise Unix style command line flags?

The problem is that 'erl' is interpreting the args. A possibly
solution would be to put a leading "escape" character on them so that
erl never sees anything starting with "-".

My quick hack is this. First a new script that escapes the args:

  #!/bin/sh
  function escape() {
    for arg in $*; do echo -n "\\${arg} "; done
    echo ""
  }

  erl -pa /home/luke/src/escript-1.0 -noshell -s escript go $0 $(escape $*)

Then the erlang module needs to strip the escape characters:

  go(X0) ->
      X = map(fun(I) ->
                      [_EscapeChar | Arg] = atom_to_list(I),
                      Arg
              end, X0),
      [_,F|Args] = X,
      ... etc

This works for me:

  $ cmd-line-args -foo bar -baz
  cmd-line-args ["-foo","bar","-baz"]




More information about the erlang-questions mailing list