How can i execute a shell (bash) command within a Common Lisp program and assign the output to a variable?
Seems like ${variable} is the same as $variable , while $() is to execute a command.
Again, $() is a command substitution which means that it “reassigns the output of a command or even multiple commands; it literally plugs the command output into another context” (Source).
ITA has released inferior-shell under their QITAB umbrella project.
Some links of possible interest :
A git repository is currently hosted at common-lisp.net :
git clone git://common-lisp.net/projects/qitab/inferior-shell.git
ASDF provides a RUN-SHELL-COMMAND
that works with many Common Lisp implementations including ABCL, Allegro CL, CLISP, Clozure CL, ECL, GCL, LispWorks, SBCL, CMU, XCL and SCL.
It takes a control string and a list of arguments like FORMAT
, and synchronously executes the result using a Bourne-compatible shell. Capture output by binding an optional stream.
You can consider using Trivial-shell (url)
(trivial-shell:shell-command "echo foo")
shell-command returns output, so you can assign it to a variable.
In asdf.lisp file you can read:
;;;; We probably should move this functionality to its own system and deprecate
;;;; use of it from the asdf package. However, this would break unspecified
;;;; existing software, so until a clear alternative exists, we can't deprecate
;;;; it, and even after it's been deprecated, we will support it for a few
;;;; years so everyone has time to migrate away from it. -- fare 2009-12-01
Nowadays I would use uiop:run-program
, where uiop
stands for "universal input output" and is a compatibility layer provided by asdf3, formerly known as asdf/driver
. As has been said asdf:run-shell-command
is obsolete and uiop inherits many features of other libraries such as trivial-shell
.
UIOP readme
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With