Skip to content

Instantly share code, notes, and snippets.

@KeenS KeenS/script.lisp
Last active Dec 13, 2016

Embed
What would you like to do?
A function for shelly to load a file ignoring shebang. This is useful to write a script with Common Lisp.
(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
You can’t perform that action at this time.