Issue using shebang to run SBCL Common LISP script as executable
Asked Answered
P

3

6

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.

Peptonize answered 11/3, 2019 at 7:58 Comment(3)
What kind of machine are you attempting to run this on? – Lifeanddeath
If Linux/UNIX, is the file marked as executable (chmod +x)? If Windows, is sbcl.exe in your system PATH? – Furcula
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 – Lifeanddeath
M
5

had same problem on MacOS, changed to:

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

worked.

Magnetograph answered 8/9, 2020 at 18:16 Comment(0)
Z
4

Using GNU Core Utilities on Arch Linux here:

#!/usr/bin/env -S sbcl --script
(write-line "😻")
Zsazsa answered 7/3, 2021 at 16:12 Comment(0)
C
0

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 !
Crutcher answered 21/5, 2019 at 22:58 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.