script invocation

Q&A's, tips, howto's
Locked
ggeorgalis
Posts: 8
Joined: Tue Nov 16, 2010 7:08 am
Location: Mountain View, California

script invocation

Post by ggeorgalis »

How is a newlisp script invoked?

newlisp <demo.lsp

works as expected; but creating demo.lsp as an executable file starting with "#!/usr/bin/env newlisp" is not intrepeting the content???

./demo.lsp
newlisp demo.lsp

it goes interactive. does the interpreter require newlisp scripts to be fed as stdin?

-George

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: script invocation

Post by Lutz »

Yes, like this:

./demo.lsp
newlisp demo.lsp

... and make sure scripts end with '(exit)'. If not you end up in the interactive command line, and '#!/usr/bin/env newlisp' will works as expected if the file has executable permissions.

Here are examples for Unix filters and pipes:

http://www.newlisp.org/downloads/CodePa ... html#toc-2

ggeorgalis
Posts: 8
Joined: Tue Nov 16, 2010 7:08 am
Location: Mountain View, California

Re: script invocation

Post by ggeorgalis »

okay, excellent, that's resolved. I wasn't expecting the exit function as a requirement.

do you know anyway to coerce options into interpreter without using the full path? Is there a possibility of setting them within the script, like the shell set function? I'd like to use

#!/usr/bin/env newlisp -s 100000 -m 10

but that fails, env is somehow interpreting the options as part of the filename. "#!/usr/bin/env newlisp" works fine.

#!/usr/local/newlisp-10.2.8./bin/newlisp-10.2.8 -s 100000 -m 10

works but I don't want to hard code the path in the script.

-George

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: script invocation

Post by Lutz »

It very much depends on the UNIX flavor how these things are handled. E.g. the following script:

Code: Select all

#!/usr/bin/env newlisp -s 123456

(println (main-args))
(println (sys-info))

(exit)
works fine on Mac OS X (a BSD-like UNIX flavor):

Code: Select all

$ ./script 
("newlisp" "-s" "123456" "./script")
(457 268435456 389 2 0 123456 0 613 10217 131)
$
but fails on FreeBSD:

Code: Select all

$ ./script
env: newlisp -s 123456: No such file or directory
$

... and would work on FreeBSD with the absolute path: #!/usr/local/bin/newlisp -s 123456

... and SunOS will completely ignore options in the header line:

Code: Select all

$ ./script 
("newlisp" "./script")
(312 268435456 300 2 0 1024 8500 4)    <-- running an older version with different sys-info format
$ 
the install should supply a link newlisp -> newlisp-10.2.8, so you don't need the version number when using an absolute path in the header line.

Locked