3

E.g., one I could use by adding a shebang to my Pascal files:

#!/usr/bin/env fpi
Matt Hulse
  • 5,496
  • 4
  • 29
  • 37
mcandre
  • 22,868
  • 20
  • 88
  • 147

1 Answers1

5

There's instantfpc at fpc's svn trunk: http://svn.freepascal.org/svn/fpc/trunk/utils/instantfpc/

Here's the README:

instantfpc
==========

This tool allows to execute pascal programs as unix scripts.
A unix script starts with a shebang #! and the program to execute. For example

#!/usr/bin/env instantfpc
begin
  writeln('It works');
end.

If you save the above file as test.pas and set the execute permission
(chmod a+x) you can execute the script simply with
./test.pas


Installation
============

1. Compile instantfpc.lpi using lazarus, lazbuild or via "fpc instantfpc.lpr"
2. Put the executable "instantfpc" in PATH, for example into
   /usr/bin/instantfpc or ~/bin/instantfpc.

That's all.
Now you can execute pascal programs as scripts.
mkriheli
  • 1,788
  • 10
  • 18
  • Thanks! Unfortunately, `fpc` can't compile code with shebangs, but I look forward to a future version that treats them as comments. – mcandre Oct 14 '11 at 22:48
  • Yes. instantfpc removes the shebang before compiling it (procedure CommentShebang in instantfptools.pas). – mkriheli Oct 14 '11 at 22:56
  • That's only a workaround--fpc itself can't handle shebangs, so you have to decide for every .PAS file whether you want to run it as a script or compile it. – mcandre Oct 15 '11 at 00:40
  • 1
    Yes, that's true. As a short time solution guess one can write a wrapper around fpc and removes shebangs. – mkriheli Oct 15 '11 at 22:17