Code Snippets

Category: CLI & System

Install a Cron Job from a Script

Append a cron line idempotently with grep -q before crontab.

Author: chris

Parse Args with getopts

Stdlib short-option parsing with the `getopts` builtin.

Author: chris

Trap SIGINT for Cleanup

Use `trap` to remove a tempdir even when the user hits Ctrl-C.

Author: chris

Check if a Command Exists

Use `command -v` — portable, no subshell, returns nonzero if missing.

Author: chris

Parse argv in a PHP CLI Script

Hand-roll CLI parsing using \$argv when getopt is overkill.

Author: chris

Parse Flags with the flag Package

Parse typed CLI flags using the stdlib flag package.

Author: chris