【问题标题】:Issue using shebang to run SBCL Common LISP script as executable使用 shebang 将 SBCL Common LISP 脚本作为可执行文件运行的问题
【发布时间】:2019-03-11 07:58:06
【问题描述】:

我一直在尝试使用 SBCL 学习 Common Lisp,但在执行我的代码时遇到了问题。使用sbcl --script exec.lisp 一切正常(无论我是否指定了shebang 行),但我似乎无法直接使用shebang 行执行与./exec.lisp 相同的文件。虽然我很可能误解了manual 所做的事情,但我的理解暗示这应该是可能的。我的exec.lisp 脚本看起来与示例中的脚本相同(并且它已被赋予可执行权限chmod a+x exec.lisp

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

但我收到的不是所需的输出:

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

我已经确定sbcl 的路径是正确的)

编辑:我使用的是 mac OS。

【问题讨论】:

  • 你试图在什么样的机器上运行它?
  • 如果是 Linux/UNIX,文件是否标记为可执行文件 (chmod +x)?如果是 Windows,sbcl.exe 在您的系统路径中吗?
  • 是的,这就是我要问的。如果这是 Windows,您必须确保使用 sbcl bin 文件夹更新您的环境变量,以便从命令行运行 sbcl。这是一个更好的问题,但是可以通过教程来回答。您可能还需要考虑使用运行 sbcl 的 emacs 设置 ide

标签: common-lisp sbcl shebang


【解决方案1】:

在 MacOS 上遇到同样的问题,改为:

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

工作。

【讨论】:

    【解决方案2】:

    在 Arch Linux 上使用 GNU Core Utilities:

    #!/usr/bin/env -S sbcl --script
    (write-line "?")
    

    【讨论】:

      【解决方案3】:

      我会检查为sbcl 提供的路径(它是否与which sbcl 的输出匹配?)

      我尝试了以下方法(运行 MacOS Mojave 10.14.4,SBCL 版本 1.4.16,使用 nix 而不是 brew 获得,但我怀疑这会有所不同):

      > $ 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 !
      

      【讨论】:

        猜你喜欢
        • 2011-06-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-30
        • 2023-03-27
        • 1970-01-01
        • 1970-01-01
        • 2020-01-26
        相关资源
        最近更新 更多