3
votes

I'm tyring to run a Common Lisp shebang script (test.lisp) on MacOS using SBCL. The script is below:

#!/usr/local/bin/Cellar/sbcl/1.5.6/bin/sbcl --script
(write-line "test")

I ran chmod +x on the script to make it executable, and when I run it I get:

./test.lisp: line 2: write-line: command not found

I made sure my SBCL path was correct. I originally tried /usr/local/bin/sbcl, but that gave me the same error.

How can I fix this?

1
It's a very bad idea to put such a specific path into the shebang as version 1.5.6 will get updated and that command will fail, so you are better off using #!/usr/bin/env sbcl and you probably don't need --script (not sure - don't know anything about lisp). What happens when you run /usr/bin/local/Cellar/sbcl/1.5.6/bin/sbcl --script test.lisp? If you get the same effect then it's not a shebang issue. - trojanfoe
Using #!/usr/bin/env sbcl --script worked! I did need the --script, or it just threw me into the SBCL repl. Thanks much - maknel
I think you had /usr/local/bin mixed-up with /usr/bin/local anyway. - trojanfoe
That was just a typo in the post, thank you for pointing it out - maknel

1 Answers

3
votes

Do not use such specific paths in shebang script lines, especially if they contain version numbers, as the location/version of those binaries are likely to change and break the script.

Instead use /usr/bin/env to find the executable, and in your case that's:

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