Last active
December 13, 2016 07:13
-
-
Save KeenS/6688683 to your computer and use it in GitHub Desktop.
A function for shelly to load a file ignoring shebang. This is useful to write a script with Common Lisp.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(in-package :shelly) | |
(export (defvar *argv* nil)) | |
(in-package :cl-user) | |
(defun script (file argv) | |
"Execute a file as script ignoring shebang" | |
(setf shelly:*argv* argv) | |
(let* ((in (open file :if-does-not-exist :error)) | |
(first-char (read-char in)) | |
(second-char (read-char in))) | |
(cond | |
((and (char= first-char #\#) (char= second-char #\!)) | |
(read-line in)) | |
(t (unread-char second-char in) | |
(unread-char first-char in))) | |
(load in) | |
(values))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment