Use cases
This page show some common code snippets to easily quickstart single file portable script.
Usage with clish
To make a portable CLI script with clish:
#!/bin/bash
# Load shxt.sh
. shxt.sh || eval "$(curl -v https://mrjk.github.io/shxt/shxt.sh)"
# eval "$(cat ../shxt.sh)"
# Load clish
# See: https://github.com/mrjk/clish
loader use lib clish https://raw.githubusercontent.com/mrjk/clish/refs/heads/main/clish.bash
# Define your clish commands
cli__hello ()
{
: "help=Show word string"
echo "World"
}
cli__test1 ()
{
: "help=Show word string"
: "args=NAME [FILE]"
[[ "$#" != 0 ]] || _script_die 6 "Missing name for command: test1"
echo "Name: $1"
echo "File: ${2:-<NO_FILE>}"
}
# Load clish
clish_init "$@"
Then, make this script executable:
Then you can run your script: