title: How to run SWI-Prolog from the command line?
body: <p>Is there a way to just create a prolog script called <code>hello.pl</code> like this:</p>
  
  <pre><code>#!/usr/local/bin/swipl -q -s -t main
  
  main:-
    write('Hello World\n').
  </code></pre>
  
  <p>And be able to run it from the terminal like this?</p>
  
  <pre><code>$ hello.pl
  Hello World
  $
  </code></pre>
  
  <p>When I do that it gives me this:</p>
  
  <pre><code>hello.pl: line 3: main:-: command not found
  hello.pl: line 4: syntax error near unexpected token `'Hello World\n''
  hello.pl: line 4: `  write('Hello World\n').'
  </code></pre>
  
  <p>I am able to get it working by writing this on the command line:</p>
  
  <pre><code>$ swipl -q -f hello.pl -t main
  Hello World
  $
  </code></pre>
  
  <p>But is there a way to just run the straight script as an executable instead?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Haven't yet been able to get this to work. Here is the output from the commands @Boris asked in the comments in his answer:</p>
  
  <pre><code>$ ls -l
  total 8
  -rwxr-xr-x  1 viatropos  staff  235 Aug 26 20:28 example.pl
  $ cat example.pl
  #!/usr/local/bin/swipl
  
  :- set_prolog_flag(verbose, silent).
  
  :- initialization main.
  
  main :-
      format('Example script~n'),
      current_prolog_flag(argv, Argv),
      format('Called with ~q~n', [Argv]),
      halt.
  main :-
      halt(1).
  $ which swipl
  /usr/local/bin/swipl
  $ swipl --version
  SWI-Prolog version 6.6.6 for x86_64-darwin13.1.0
  $ ./example.pl
  ./example.pl: line 3: syntax error near unexpected token `('
  ./example.pl: line 3: `:- set_prolog_flag(verbose, silent).'
  $
  </code></pre>
  
  <p>I am on Mac OSX 10.9.2, and installed swipl with homebrew via <code>brew install swi-prolog --with-libarchive</code></p>