Generate POSIX shell scripts following UNIX programming principles and a rigorous coding style. Use when: (1) creating or updating shell scripts; (2) when working on .sh files; (3) when working on files with #!/bin/sh shebang lines. Do not use when: (1) asked to create a Bash script.
Generates POSIX-compliant shell scripts following UNIX philosophy and rigorous coding standards. Use when creating or editing .sh files with #!/bin/sh shebangs, but not for Bash scripts.
/plugin marketplace add SuperScript/scrip/plugin install scrip@sst-scripThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/template.shreferences/patterns.mdreferences/style-guide.mdscripts/init-script.shGenerate POSIX-compliant shell scripts that follow UNIX philosophy and rigorous engineering practices.
Apply these principles to all shell scripts:
"${var}", "$@")#include directives for reusable components#_# prefix for help textEvery script follows this template:
#!/bin/sh
#### template functions
#include "shout.sh"
#include "barf.sh"
#include "usage.sh"
#include "do_help.sh"
#### program functions
#_# command args...
#_# Description of command
#_#
do_command() {
# implementation
}
#### parameters
# Configuration variables here
#### main
test $# -gt 0 || usage "$0 command [args]"
"do_$@"
shout() { printf '%s\n' "$0: $*" >&2; } # Print to stderr
barf() { shout "fatal: $*"; exit 111; } # Fatal error, exit 111
usage() { shout "usage: $*"; exit 100; } # Usage error, exit 100
# Correct - always quote, use braces for multi-character names
local filename="$1"
test -f "${filename}"
"${command}" "${arg1}" "${arg2}"
# Single-digit positional parameters don't need braces
shift_count="$1"
process "$2" "$3"
# Special cases
"$@" # All args as separate quoted words
"$*" # All args as single word
$# # Number of args (safe unquoted)
$? # Exit code (safe unquoted)
$$ # Process ID (safe unquoted)
# Exception: Intentional unquoted usage must be commented
for file in ${pattern} # intentional: word splitting needed
do
process "${file}"
done
#_# build
#_# Build the project
#_#
do_build() {
make
}
#_# test
#_# Run tests
#_#
do_test() {
./run-tests
}
#### main
test $# -gt 0 || usage "$0 build|test|help"
"do_$@"
#include "atomic_to.sh"
# Write atomically: creates temp → writes → moves
atomic_to "output.txt" sed 's/foo/bar/g' input.txt
atomic_to "config.json" jq '.setting = "value"' raw.json
# Fail on error
command || barf "command failed"
# Check file exists
test -f "$file" || barf "file not found: $file"
# Validate arguments
test $# -eq 2 || usage "$0 source dest"
#include "pipeline.sh"
# Build pipelines with custom separator
pipeline '::' cat file.txt '::' grep pattern '::' sort
The assets/stdlib/ directory contains reusable shell functions:
Core Functions:
shout.sh - Print messages to stderrbarf.sh - Fatal error handlingusage.sh - Usage error handlingdo_help.sh - Self-documenting help extractionFile Operations:
atomic_to.sh - Atomic file writesatomic_to_mode.sh - Atomic writes with permissionsUtilities:
pipeline.sh - Pipeline constructionpipewith.sh - Flexible pipeline buildercatch.sh - Error pattern detectionsafe.sh - Safe command executiondo_.sh - Subcommand dispatcherdo_run.sh, do_xrun.sh - Command runnershave_args.sh - Argument validationInclude these in scripts using #include directives:
#include "shout.sh"
#include "barf.sh"
#include "atomic_to.sh"
For comprehensive guidelines and patterns:
Read these references when:
Use assets/template.sh as a starting point for new scripts. It includes:
Run scripts/init-script.sh to create new scripts:
scripts/init-script.sh my-script output-dir/
Creates a properly structured script ready for implementation.
Use consistent exit codes:
assets/template.sh or run scripts/init-script.sh#include directives for needed utilitiesdo_* functions with #_# help textbarf() and usage() work correctlyUse template with basic includes (shout, barf, usage, do_help)
Include atomic_to.sh for safe file operations
Include pipeline.sh and pipewith.sh for composable commands
Use subcommand pattern with do_* functions and main dispatcher
Combine atomic operations, error checking, and subcommand dispatch