2017-08-30 33 views
1

假设我有一个名为“1.sb”这个内容的文件:在SBCL检索脚本名称

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

(prin1 sb-ext:*posix-argv*) (terpri) 

如果我调用它作为“1.sb ABC”我得到这样的输出:

("/usr/local/bin/sbcl" "a" "b" "c") 

如何获取脚本文件本身的名称('1.sb')?

回答

0

事实证明,对SBCL,正确的(至少据我可以告诉),轻量级的解决办法是在此脚本:

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

(prin1 (apply #'concatenate 'string 
     (remove-if #'null 
      (list (pathname-name *load-truename*) 
       (when (pathname-type *load-truename*) 
        ".") 
       (pathname-type *load-truename*))))) (terpri) 

the Freebsd forums感谢用户tobik指着我*负载truename *。