Scripting
Misc scripting things
Hush Lang Link to heading
New scripting language: https://hush-shell.github.io/
- Written in Rust
- Strongly Typed, Garbage collected, 1st class shell capabilities
- Syntax a mix of Go, Rust, and Typescript; “Inspired by Lua”
- Provides standard library
std
with common functions and constants - Proper
if
,for
, andwhile
. Built inlist
anddict
types. dict
can have function values for keys (aka “a method” sort of)- syntax errors
panic
and app errors returnstd.error("...")
- adding a
?
to something which may return an error panics if an error is returned.
- adding a
- execute commands in “command blocks”:
{ touch /etc/config }
- can return a proper “std.error” type or a result
- multiple commands per block delimited by
;
- supports pipelines and redirection using standard syntax
- variables defined outside can be used using
$var
/${var}
/ etc. - error in any command stops unless followed by a
?
(opposite behavior to in normal lang)
- supports launching command blocks async using
let handle = &{...}
andhandle.join()
to wait for completion
function run()
{ mkdir /etc/config/ }?
std.print("Success!") # This won't be executed if the command block fails.
end
let result = run()
if std.type(result) == "error" then
std.print("Error: ", result)
end
Bash one-line script; Print “sleep” every 10 seconds forever Link to heading
bash -c while true; do echo sleep; sleep 10;done && echo done
Needed this once because I needed to run a custom command in a Fargate task with two “essential” containers. One of those containers would exit immediately which would interrupt the other command which was migrating the database so I wrote this up to have it “do nothing” without spending too much CPU.