You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派下如何在命令行运行SBCL Lisp代码文件?

解决SBCL脚本无法直接运行的问题

问题描述

我在树莓派上通过以下命令安装了SBCL:

pi# apt install sbcl

发现和clisp不同,在文件顶部添加#!/usr/bin/sbcl后,没法直接从命令行运行Lisp脚本。我的问题是:把Lisp代码写入名为test的文件后,需要做哪些操作(比如修改文件、编译等)才能在命令行直接运行?

终端操作及输出详情:

pi@raspberrypi:~/SBCL $ cat test
#!/usr/bin/sbcl

(defun HI()
(let (vx 0)
(setf vx (+ (* 3 5) (mod 27 7)))
(format t "~a~%" vx)
))

(HI)

pi@raspberrypi:~/SBCL $ ls -l test 
  -rwxr-xr-x 1 pi pi 104 Dec  2 05:41 test
pi@raspberrypi:~/SBCL $ ./test 
This is SBCL 2.2.9.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* 

解决步骤

  • 修改脚本文件的shebang行,添加--script参数,改为:
    #!/usr/bin/sbcl --script
    
  • 确保文件拥有可执行权限(你已经通过chmod +x test设置好了,若未设置可执行此命令)
  • 直接运行./test即可,此时SBCL会执行文件内的代码并自动退出,不会进入交互模式。

原因说明

SBCL默认启动时会进入交互式REPL环境,而--script参数会告诉SBCL以脚本模式运行:读取并执行文件中的代码,执行完成后立即退出,不会停留在交互提示符。这和clisp的默认行为不同,clisp不加额外参数就能直接执行脚本。

内容的提问来源于stack exchange,提问作者Michel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 19:15:59