6
votes

I've been trying to learn Common Lisp with SBCL and I've ran into issues executing my code. Everything works fine using sbcl --script exec.lisp (regardless of if I have specified a shebang line) but I can't seem to execute the same file with a shebang line directly as ./exec.lisp. While I've most likely misunderstood something the manual does from my understanding imply that this should be possible. My exec.lisp script looks identical to the one in the example (and it has been given executable privileges chmod a+x exec.lisp)

#!/usr/local/bin/sbcl --script
(write-line "Hello, World!")

but instead of the desired output I receive :

$ ./exec.lisp 
./exec.lisp: line 2: write-line: command not found

I've made sure that the path to sbcl is correct)

EDIT: I'm using mac OS.

3
What kind of machine are you attempting to run this on? - Simeon Ikudabo
If Linux/UNIX, is the file marked as executable (chmod +x)? If Windows, is sbcl.exe in your system PATH? - R Y
Yep, that's what I was about to ask. If this is windows, you have to make sure to update your environment variables with the sbcl bin folder in order to run sbcl from the command line. This is a better question that can be answered with a tutorial however. You may also want to consider setting up an ide with emacs running sbcl - Simeon Ikudabo

3 Answers

4
votes

had same problem on MacOS, changed to:

#!/usr/bin/env sbcl --script

worked.

3
votes

Using GNU Core Utilities on Arch Linux here:

#!/usr/bin/env -S sbcl --script
(write-line "😻")
0
votes

I would check the path supplied for sbcl (does it match the output of which sbcl ?)

I tried the following (running MacOS Mojave 10.14.4, SBCL version 1.4.16, obtained using nix instead of brew, but I doubt that makes a difference):

> $ which sbcl
/Users/abrahma/.nix-profile/bin/sbcl

> $ bat test.lisp
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: test.lisp
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ #!/Users/abrahma/.nix-profile/bin/sbcl --script
   2   │ (write-line "Hello world from Lisp !")
   3   │
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

> $ l
.rwxr-xr-x 88 abrahma 21 May 15:54 test.lisp

> $ ./test.lisp
Hello world from Lisp !