{"kind":"AgentDefinition","metadata":{"namespace":"community","name":"shell","version":"0.1.0"},"spec":{"agents_md":"---\ndescription: 'Shell scripting best practices and conventions for bash, sh, zsh, and other shells'\napplyTo: '**/*.sh'\n---\n\n# Shell Scripting Guidelines\n\nInstructions for writing clean, safe, and maintainable shell scripts for bash, sh, zsh, and other shells.\n\n## General Principles\n\n- Generate code that is clean, simple, and concise\n- Ensure scripts are easily readable and understandable\n- Add comments where helpful for understanding how the script works\n- Generate concise and simple echo outputs to provide execution status\n- Avoid unnecessary echo output and excessive logging\n- Use shellcheck for static analysis when available\n- Assume scripts are for automation and testing rather than production systems unless specified otherwise\n- Prefer safe expansions: double-quote variable references (`\"$var\"`), use `${var}` for clarity, and avoid `eval`\n- Use modern Bash features (`[[ ]]`, `local`, arrays) when portability requirements allow; fall back to POSIX constructs only when needed\n- Choose reliable parsers for structured data instead of ad-hoc text processing\n\n## Error Handling \u0026 Safety\n\n- Always enable `set -euo pipefail` to fail fast on errors, catch unset variables, and surface pipeline failures\n- Validate all required parameters before execution\n- Provide clear error messages with context\n- Use `trap` to clean up temporary resources or handle unexpected exits when the script terminates\n- Declare immutable values with `readonly` (or `declare -r`) to prevent accidental reassignment\n- Use `mktemp` to create temporary files or directories safely and ensure they are removed in your cleanup handler\n\n## Script Structure\n\n- Start with a clear shebang: `#!/bin/bash` unless specified otherwise\n- Include a header comment explaining the script's purpose\n- Define default values for all variables at the top\n- Use functions for reusable code blocks\n- Create reusable functions instead of repeating similar blocks of code\n- Keep the main execution flow clean and readable\n\n## Working with JSON and YAML\n\n- Prefer dedicated parsers (`jq` for JSON, `yq` for YAML—or `jq` on JSON converted via `yq`) over ad-hoc text processing with `grep`, `awk`, or shell string splitting\n- When `jq`/`yq` are unavailable or not appropriate, choose the next most reliable parser available in your environment, and be explicit about how it should be used safely\n- Validate that required fields exist and handle missing/invalid data paths explicitly (e.g., by checking `jq` exit status or using `// empty`)\n- Quote jq/yq filters to prevent shell expansion and prefer `--raw-output` when you need plain strings\n- Treat parser errors as fatal: combine with `set -euo pipefail` or test command success before using results\n- Document parser dependencies at the top of the script and fail fast with a helpful message if `jq`/`yq` (or alternative tools) are required but not installed\n\n```bash\n#!/bin/bash\n\n# ============================================================================\n# Script Description Here\n# ============================================================================\n\nset -euo pipefail\n\ncleanup() {\n    # Remove temporary resources or perform other teardown steps as needed\n    if [[ -n \"${TEMP_DIR:-}\" \u0026\u0026 -d \"$TEMP_DIR\" ]]; then\n        rm -rf \"$TEMP_DIR\"\n    fi\n}\n\ntrap cleanup EXIT\n\n# Default values\nRESOURCE_GROUP=\"\"\nREQUIRED_PARAM=\"\"\nOPTIONAL_PARAM=\"default-value\"\nreadonly SCRIPT_NAME=\"$(basename \"$0\")\"\n\nTEMP_DIR=\"\"\n\n# Functions\nusage() {\n    echo \"Usage: $SCRIPT_NAME [OPTIONS]\"\n    echo \"Options:\"\n    echo \"  -g, --resource-group   Resource group (required)\"\n    echo \"  -h, --help            Show this help\"\n    exit 0\n}\n\nvalidate_requirements() {\n    if [[ -z \"$RESOURCE_GROUP\" ]]; then\n        echo \"Error: Resource group is required\"\n        exit 1\n    fi\n}\n\nmain() {\n    validate_requirements\n\n    TEMP_DIR=\"$(mktemp -d)\"\n    if [[ ! -d \"$TEMP_DIR\" ]]; then\n        echo \"Error: failed to create temporary directory\" \u003e\u00262\n        exit 1\n    fi\n    \n    echo \"============================================================================\"\n    echo \"Script Execution Started\"\n    echo \"============================================================================\"\n    \n    # Main logic here\n    \n    echo \"============================================================================\"\n    echo \"Script Execution Completed\"\n    echo \"============================================================================\"\n}\n\n# Parse arguments\nwhile [[ $# -gt 0 ]]; do\n    case $1 in\n        -g|--resource-group)\n            RESOURCE_GROUP=\"$2\"\n            shift 2\n            ;;\n        -h|--help)\n            usage\n            ;;\n        *)\n            echo \"Unknown option: $1\"\n            exit 1\n            ;;\n    esac\ndone\n\n# Execute main function\nmain \"$@\"\n\n```\n","description":"Shell scripting best practices and conventions for bash, sh, zsh, and other shells","import":{"commit_sha":"541b7819d8c3545c6df122491af4fa1eae415779","imported_at":"2026-05-18T20:05:35Z","license_text":"MIT License\n\nCopyright GitHub, Inc.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","owner":"github","repo":"github/awesome-copilot","source_url":"https://github.com/github/awesome-copilot/blob/541b7819d8c3545c6df122491af4fa1eae415779/instructions/shell.instructions.md"},"manifest":{}},"content_hash":[131,104,196,139,12,220,68,46,90,105,220,169,61,174,227,135,8,179,246,202,36,162,160,84,176,172,145,227,8,209,23,103],"trust_level":"unsigned","yanked":false}
