agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/languages/bash/SKILL.md

bash

Skill15 starsChanged 42 days agoMITView on GitHub

Expert Bash shell scripting assistance covering POSIX compliance, parameter expansion, pipelines, traps, and debugging. Use when writing robust shell scripts, automating DevOps tasks, or handling file processing.

  • Deletes or force-pushes

8 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 2 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 6 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use unofficial bash strict mode with automatic cleanup trap:

    line 85
  2. Very specific:

    Always Quote Variables: Wrap variables in double quotes ("${MY_VAR}") to prevent word splitting and glob expansion bugs.

    line 107
  3. Very specific:

    Use [[ ... ]] for Conditions: Prefer modern Bash conditional evaluation [[ $var == "val" ]] over legacy [ ...

    line 109
  4. Very specific:

    Use Local Variables in Functions: Always declare variables inside functions with local var="value".

    line 110
  5. Very specific:

    Use unquoted eval: eval executes arbitrary string inputs and introduces catastrophic shell injection vulnerabilities.

    line 115
  6. Distinctive:

    Write multi-thousand line monolithic bash scripts: Transition complex scripts to Python or Go when logic grows large.

    line 116

“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Bash

Bourne Again SHell, the standard shell for Linux and macOS.

When to Use

  • Linux System Administration & Automation: Scripting OS maintenance, cron jobs, file backups, and package management.
  • CI/CD Pipeline Glue Code: Orchestrating build, test, and container push steps in GitHub Actions and GitLab CI.
  • Docker Entrypoint Scripts: Configuring environment variables, secrets, and database wait-for loops during container startup.
  • Command-Line Wrappers: Wrapping multi-step CLI commands into simple, repeatable internal developer utilities.

Quick Start

#!/bin/bash

NAME="World"
echo "Hello, $NAME!"

if [ -f "file.txt" ]; then
    echo "File exists"
else
    echo "File not found"
fi

Core Concepts

Strict Error Handling (set -euo pipefail)

Guarantees script execution aborts on unhandled errors, unset variables, and piped command failures:

#!/usr/bin/env bash
set -euo pipefail
IFS=$'
	'

# -e: Exit immediately if a command exits with a non-zero status
# -u: Treat unset variables as an error and exit immediately
# -o pipefail: Pipeline exit status matches the last failing command

Robust Parameter Expansion & Default Values

Safely handles optional and required script variables:

# Provide fallback default if variable unset
TARGET_ENV="${1:-staging}"

# Throw descriptive error if variable is unset or empty
DATABASE_URL="${DATABASE_URL:?Error: DATABASE_URL environment variable is required}"

# Extract filename without extension
filename="archive_2026.tar.gz"
base="${filename%%.*}" # "archive_2026"

Trap Signals for Reliable Cleanup

Ensures temporary files and child processes are cleaned up upon exit or interruption:

TEMP_DIR="$(mktemp -d)"
cleanup() {
  echo "Cleaning up temporary files..."
  rm -rf "${TEMP_DIR}"
}
trap cleanup EXIT INT TERM

Common Patterns

Safe Script Header with Error and Signal Traps

Problem: Shell scripts fail silently halfway through, leaving orphaned temp files and corrupted state.

Solution: Use unofficial bash strict mode with automatic cleanup trap:

#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

TMP_DIR=$(mktemp -d)
cleanup() {
    rm -rf "$TMP_DIR"
    echo "Cleaned up temporary workspace."
}
trap cleanup EXIT ERR INT TERM

# Script business logic
echo "Working in: $TMP_DIR"

Best Practices

Do:

  • Always Quote Variables: Wrap variables in double quotes ("${MY_VAR}") to prevent word splitting and glob expansion bugs.
  • Lint with ShellCheck: Run shellcheck in CI to catch syntax pitfalls, portability bugs, and quoting errors automatically.
  • Use [[ ... ]] for Conditions: Prefer modern Bash conditional evaluation [[ $var == "val" ]] over legacy [ ... ].
  • Use Local Variables in Functions: Always declare variables inside functions with local var="value".

Don't:

  • Parse ls output: Use globbing loops (for file in *.txt; do ... done) instead of parsing ls.
  • Use unquoted eval: eval executes arbitrary string inputs and introduces catastrophic shell injection vulnerabilities.
  • Write multi-thousand line monolithic bash scripts: Transition complex scripts to Python or Go when logic grows large.

Troubleshooting

ErrorCauseSolution
syntax error: unexpected end of fileUnclosed quotes, missing fi, done, or unbalanced parentheses.Run bash -n script.sh to validate syntax without executing.
command not found: $'\r'Windows CRLF line endings present in shell script.Convert line endings with dos2unix script.sh.
unbound variable (with set -u)Referencing unset environment or script variable.Provide default value: ${VAR:-default_val}.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.