Skip to content

Instantly share code, notes, and snippets.

@southly
Created March 14, 2009 14:31
Show Gist options
  • Save southly/79081 to your computer and use it in GitHub Desktop.
Save southly/79081 to your computer and use it in GitHub Desktop.
#!/opt/local/bin/sbcl --script
(write-line "Hello, World!")
;; --script オプションを付ける
;; version 1.0.22 以降
;; http://www.sbcl.org/manual/Shebang-Scripts.html
;; http://www.sbcl.org/manual/Saving-a-Core-Image.html
;; http://www.sbcl.org/manual/Support-For-Unix.html
;; http://www.sbcl.org/manual/Quit.html
#!/opt/local/bin/sbcl --script
(format *standard-output* "~{~A~^ ~}~%" (cdr *posix-argv*))
;; スクリプトの引数は sb-ext:*posix-argv* にリストとして入っている
;; ただし、ひとつめは sbcl のパス
#!/opt/local/bin/sbcl --script
(print *load-pathname*)
(print *load-truename*)
;; スクリプトファイルのパスは
;; - *load-pathname*
;; - *load-truename*
;; に入っている
#!/opt/local/bin/sbcl --script
(format t "Read Line: ")
(force-output)
(format t "Input : ~A~%" (read-line *standard-input*))
(terpri *standard-output*)
(write-line "stdout" *standard-output*)
(terpri *standard-output*)
(write-line "stderr" *error-output*)
;; *standard-input* : 標準入力
;; *standard-output* : 標準出力
;; *error-output* : 標準エラー出力
#!/opt/local/bin/sbcl --script
(format t "Read Line: ")
(force-output)
(let ((n (parse-integer (read-line *standard-input*) :junk-allowed t)))
; (sb-ext:quit :recklessly-p t :unix-status n)
(sb-unix:unix-exit n)
)
;; exit status を指定したい場合は sb-unix:unix-exit を使用
;; sb-ext:quit の :unix-status パラメータを使用する方法もあり
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment