Trivial bash shell for common lisp
December 11, 2024 —
shinohai
I recently acquired a fresh laptop, and in the process of setting up sbcl I thought I best polish this little lisp function for my .sbclrc. I shall publish it here lest I forget it, and on the off chance another reader finds it useful.
(defun sh (cmd)
"Run a shell command and return standard output if successful."
(multiple-value-bind (stdout stderr exit)
(uiop:run-program
(format nil "~A" cmd)
:output :string
:error-output :string
:ignore-error-status t)
(if (zerop exit)
stdout
(format nil "Command failed with exit code ~A. Error: ~A" exit stderr))))
Happy holidays to all!