Babashka in Nextjournal 101 Demo
# question: Is there a human readible history of Babashka somewhere I can read?
# outdated version of Babashka
# wget https://github.com/borkdude/babashka/releases/download/v0.2.5/babashka-0.2.5-linux-amd64.zip
# outdated version of Babashka
# unzip -o babashka-0.2.5-linux-amd64 -d /usr/local/bin
# rm babashka-0.2.5-linux-amd64.zip
Skill: Download Babashka source (?)
# import the newest version of Babashka
# wget https://github.com/babashka/babashka/releases/download/v0.4.0/babashka-0.4.0-linux-amd64.tar.gz
Skill: Unzip Babashka source
# question: What needs to be changed here to correctly unzip babashka?
# tar -xvzf -o babashka-0.4.0-linux-amd64 -d /usr/local/bin
tar --help
bb --version
Skill: Delete a file
# Not sure that I want to call this a skill... I'm removing the source zip... but I could be using Babashka at this point to do so!
# rm babashka-0.4.0-linux-amd64.tar.gz
# TODO: rewrite the above line in Babashka
# STUB: remove the babashka source zip by using Babashka
Babashka Book Study, Session 001
Babashka is a scripting environment made with Clojure
Question: What are the primary use cases for scripting and scripting environments? File manipulation, text editing, etc.?
Babashka comes with batteries included and packs libraries like
clojure.tools.cli
for parsing command line arguments andcheshire
for working with JSON.
Question: Can further context be provided for what "with batteries included" means, along with counter examples?
Babashka uses sci for interpreting Clojure. Sci implements a substantial subset of Clojure.
Question: What are the key differences and gotchas between Sci and the core functionalities of Clojure?
Section 001 "Running Babashka" START
Skill: Run an expression "in-line" (?)
# question: What does the `-e` flag stand for? Execute, evaluate, expression... ?
# answer: The `-e` flag stands for "evaluate"
# From the help menu "-e, --eval <expr> Evaluate an expression."
# description: "The babashka executable is called bb."
bb -e '(+ 1 2 3)'
# "I’m looking for replacements to mv, rm, and cp. I don’t want to do this with clojure.java.shell; in that case, I would just write the bash script. Can I do it in an OS-agnostic way in Babashka?"
# source: https://clojureverse.org/t/how-to-replace-every-day-bash-commands-with-babashka/6459/3?u=avidrucker
echo "babashka" > /tmp/a
bb '(io/copy (io/file "/tmp/a") (io/file "/tmp/b"))'
cat /tmp/b
Skill: Move a file in one step without copying or deleting
# "What about bash mv? Is there a way without doing the copy and adding a delete?"
# source: https://clojureverse.org/t/how-to-replace-every-day-bash-commands-with-babashka/6459/5?u=avidrucker
bb '(.renameTo (io/file "/tmp/a") (io/file "/tmp/moved"))'
cat /tmp/moved
Skill: Save code as text into a CLJ file
echo "(+ 5 6 7)" > /tmp/script.clj
Skill: Run code from a CLJ file
# "the -f flag is optional when the argument is a filename"
# from the help menu: "-f, --file <path> Evaluate a file."
bb /tmp/script.clj
bb -f /tmp/script.clj # same as above line
Skill: Run code from script with shebang invoked by filename only
# Commonly, scripts have shebangs so you can invoke them with their filename only:
# create and write to a file called script_b.clj
# script_b.clj
echo "#!/tmp bb
(+ 1 2 3)" > /tmp/script_b.clj
# confirm that the contents are as expected
cat /tmp/script_b.clj
# skill: run code from script with shebang by invoking filename only
bb /tmp/script_b.clj
Section 001 "Running Babashka" END
Section 002
Skill: Get some help within Babashka
# skill: print the help text
bb -h
Skill: Identify what a Babashka command is doing, and to inspect when unsure
"If neither -e, -f, or --socket-repl are specified, then the first argument that is not parsed as a option is treated as a file if it exists, or as an expression otherwise. Everything after that is bound to *command-line-args*."
# question: why does this result in error?
# bb repl
# note: careful! this will never terminate and the code cell is stuck!
# question: why does this result in error?
# answer: `doc` requires an argument
# question: Is there a valid argument for `doc` to take in this notebook as it stands currently?
# bb doc
# question: why does this result in error?
bb describe
# question: What is the (meaning/significance of the) following map?
# I am trying to make an EDN or Markdown cell here, but
# typing "```markdown " or "```edn " doesn't result in those types of cells, they simply just turn into another Babashka cell
# Question: What am I do doing incorrectly here?
# question: why does this result in error?
# answer: This results in error because running Clojure requires Java which doesn't exist in Nextjournal.
# question: What is a minimum viable example of `bb clojure` used in context?
# bb clojure
bb --version
More coming soon...
Next Step
Mine for skills: https://learnxinyminutes.com/docs/bash/
Read for context: https://mywiki.wooledge.org/BashGuide
Confirm knowledge of basic skills: https://devhints.io/bash
Understand the full landscape of shell scripting: https://www.shellscript.sh/
Confirm that I know the basics: https://www.howtogeek.com/67469/the-beginners-guide-to-shell-scripting-the-basics/
Get an idea for a learning progression or "learner roadmap": https://www.guru99.com/introduction-to-shell-scripting.html
Mine for skill categories or meta-data: https://www.tutorialspoint.com/unix/shell_scripting.htm
Assess and evaluate cheatsheet: https://github.com/chubin/cheat.sh
Confirm that this mental model is accurate with an expert: https://medium.com/@varunkumar_53845/sh-vs-bash-a-summary-50f92a719e0d