Shell Expert
Expert knowledge for shell scripting, command-line tools, and automation with focus on robust, portable, and efficient solutions.
When to Use This Skill
| Use this skill when... |
Use justfile-expert instead when... |
| Authoring portable bash, zsh, or POSIX shell scripts |
Wrapping commands as named recipes for a project task runner |
| Composing pipelines and one-off automation logic |
Standardising entry points across a team or repo |
Hardening scripts with set -euo pipefail, traps, and quoting |
Defining cross-platform commands without writing shell glue |
| Use this skill when... |
Use jq-json-processing instead when... |
| Glue logic that wires together CLI tools |
The work is purely transforming JSON input |
| Writing reusable functions, argument parsing, or signal handling |
A single jq expression can replace a chain of shell commands |
Command-Line Tool Mastery
- Expert knowledge of modern CLI tools (jq, yq, fd, rg, etc.)
- JSON/YAML processing and transformation
- File searching and text manipulation
- System automation and orchestration
Shell Scripting Excellence
- POSIX-compliant shell scripting for maximum portability
- Bash-specific features and best practices
- Error handling and defensive programming
- Cross-platform compatibility (Linux, macOS, BSD)
Automation & Integration
- CI/CD pipeline scripting
- System administration automation
- Tool integration and workflow automation
- Performance optimization for shell operations
Key Capabilities
JSON/YAML Processing
- jq: Complex JSON queries, transformations, and filtering
- yq: YAML manipulation, in-place editing, format conversion
- jd: JSON diffing and patching for configuration management
- Data pipeline construction: Chaining tools for complex transformations
File Operations & Search
- fd: Fast, user-friendly file finding with intuitive syntax
- rg (ripgrep): Lightning-fast recursive grep with gitignore support
- lsd: Modern ls replacement with visual enhancements
- find/grep alternatives: When and how to use modern replacements
Shell Script Development
- Error Handling: Proper trap usage, exit codes, error propagation
- Input Validation: Argument parsing, option handling, user input sanitization
- Debugging: Set options (-x, -e, -u, -o pipefail), debug output strategies
- Performance: Process substitution, parallel execution, efficient loops
Cross-Platform Scripting
- Platform Detection: OS-specific behavior handling
- Path Management: Portable path construction and manipulation
- Tool Availability: Checking for and handling missing dependencies
- Compatibility Layers: Writing scripts that work everywhere
Automation Patterns
- Idempotent Operations: Scripts that can run multiple times safely
- Atomic Operations: Ensuring all-or-nothing execution
- Progress Reporting: User-friendly output and status updates
- Logging & Monitoring: Structured logging for automated systems
Essential Commands
jq - JSON Processing
jq . data.json # Pretty-print
jq -r '.key.subkey' data.json # Extract value
jq '.items[] | select(.status == "active")' # Filter
yq - YAML Processing
yq '.services.web.image' docker-compose.yml # Read value
yq -i '.version = "2.1.0"' config.yml # Update in-place
yq -o json config.yml # Convert to JSON
fd - Fast File Finding
fd 'pattern' # Find by pattern
fd -e md # Find by extension
fd -e sh -x shellcheck {} # Find and execute
rg - Recursive Grep
rg 'DATABASE_URL' # Basic search
rg 'TODO' -t python # Search specific file types
rg -C 3 'error' # Search with context
Best Practices
Script Development Workflow
- Requirements Analysis: Understand automation need and target platforms
- Tool Selection: Choose appropriate tools for the task
- Prototype Development: Create initial script with core functionality
- Error Handling: Add robust error handling and edge case management
- Cross-Platform Testing: Verify script works on all target systems
- Performance Optimization: Profile and optimize for efficiency
- Documentation: Add clear usage instructions and inline comments
Critical Guidelines
- Always use shellcheck for linting
- Set strict mode:
set -euo pipefail
- Quote all variables:
"${var}"
- Use functions for reusable code
- Implement proper cleanup with trap
- Provide helpful error messages
- Include --help and --version options
- Use meaningful variable names
- Comment complex logic
- Test with different shells when targeting POSIX
Common Patterns
Robust Script Template
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
trap 'echo "Error on line $LINENO"' ERR
trap cleanup EXIT
cleanup() {
rm -f "$TEMP_FILE" 2>/dev/null || true
}
main() {
parse_args "$@"
validate_environment
execute_task
}
main "$@"
Cross-Platform Detection
detect_os() {
case "$OSTYPE" in
linux*) OS="linux" ;;
darwin*) OS="macos" ;;
msys*) OS="windows" ;;
*) OS="unknown" ;;
esac
}
For detailed command-line tools reference, advanced automation examples, and troubleshooting guidance, see REFERENCE.md.
1---
2created: 2025-12-16
3modified: 2026-05-09
4reviewed: 2026-04-25
5name: shell-expert
6description: "Shell scripting: bash, zsh, POSIX, CLI tools, cross-platform automation. Use when writing shell scripts, pipes, command-line automation, or portable shell code."
7user-invocable: false
8allowed-tools: Bash, Grep, Glob, Read, Write, Edit, TodoWrite
9---
10
11# Shell Expert
12
13Expert knowledge for shell scripting, command-line tools, and automation with focus on robust, portable, and efficient solutions.
14
15## When to Use This Skill
16
17| Use this skill when... | Use justfile-expert instead when... |
18|---|---|
19| Authoring portable bash, zsh, or POSIX shell scripts | Wrapping commands as named recipes for a project task runner |
20| Composing pipelines and one-off automation logic | Standardising entry points across a team or repo |
21| Hardening scripts with `set -euo pipefail`, traps, and quoting | Defining cross-platform commands without writing shell glue |
22
23| Use this skill when... | Use jq-json-processing instead when... |
24|---|---|
25| Glue logic that wires together CLI tools | The work is purely transforming JSON input |
26| Writing reusable functions, argument parsing, or signal handling | A single jq expression can replace a chain of shell commands |
27
28**Command-Line Tool Mastery**
29- Expert knowledge of modern CLI tools (jq, yq, fd, rg, etc.)
30- JSON/YAML processing and transformation
31- File searching and text manipulation
32- System automation and orchestration
33
34**Shell Scripting Excellence**
35- POSIX-compliant shell scripting for maximum portability
36- Bash-specific features and best practices
37- Error handling and defensive programming
38- Cross-platform compatibility (Linux, macOS, BSD)
39
40**Automation & Integration**
41- CI/CD pipeline scripting
42- System administration automation
43- Tool integration and workflow automation
44- Performance optimization for shell operations
45
46## Key Capabilities
47
48**JSON/YAML Processing**
49- **jq**: Complex JSON queries, transformations, and filtering
50- **yq**: YAML manipulation, in-place editing, format conversion
51- **jd**: JSON diffing and patching for configuration management
52- **Data pipeline construction**: Chaining tools for complex transformations
53
54**File Operations & Search**
55- **fd**: Fast, user-friendly file finding with intuitive syntax
56- **rg (ripgrep)**: Lightning-fast recursive grep with gitignore support
57- **lsd**: Modern ls replacement with visual enhancements
58- **find/grep alternatives**: When and how to use modern replacements
59
60**Shell Script Development**
61- **Error Handling**: Proper trap usage, exit codes, error propagation
62- **Input Validation**: Argument parsing, option handling, user input sanitization
63- **Debugging**: Set options (-x, -e, -u, -o pipefail), debug output strategies
64- **Performance**: Process substitution, parallel execution, efficient loops
65
66**Cross-Platform Scripting**
67- **Platform Detection**: OS-specific behavior handling
68- **Path Management**: Portable path construction and manipulation
69- **Tool Availability**: Checking for and handling missing dependencies
70- **Compatibility Layers**: Writing scripts that work everywhere
71
72**Automation Patterns**
73- **Idempotent Operations**: Scripts that can run multiple times safely
74- **Atomic Operations**: Ensuring all-or-nothing execution
75- **Progress Reporting**: User-friendly output and status updates
76- **Logging & Monitoring**: Structured logging for automated systems
77
78## Essential Commands
79
80**jq - JSON Processing**
81```bash
82jq . data.json # Pretty-print
83jq -r '.key.subkey' data.json # Extract value
84jq '.items[] | select(.status == "active")' # Filter
85```
86
87**yq - YAML Processing**
88```bash
89yq '.services.web.image' docker-compose.yml # Read value
90yq -i '.version = "2.1.0"' config.yml # Update in-place
91yq -o json config.yml # Convert to JSON
92```
93
94**fd - Fast File Finding**
95```bash
96fd 'pattern' # Find by pattern
97fd -e md # Find by extension
98fd -e sh -x shellcheck {} # Find and execute
99```
100
101**rg - Recursive Grep**
102```bash
103rg 'DATABASE_URL' # Basic search
104rg 'TODO' -t python # Search specific file types
105rg -C 3 'error' # Search with context
106```
107
108## Best Practices
109
110**Script Development Workflow**
1111. **Requirements Analysis**: Understand automation need and target platforms
1122. **Tool Selection**: Choose appropriate tools for the task
1133. **Prototype Development**: Create initial script with core functionality
1144. **Error Handling**: Add robust error handling and edge case management
1155. **Cross-Platform Testing**: Verify script works on all target systems
1166. **Performance Optimization**: Profile and optimize for efficiency
1177. **Documentation**: Add clear usage instructions and inline comments
118
119**Critical Guidelines**
120- Always use shellcheck for linting
121- Set strict mode: `set -euo pipefail`
122- Quote all variables: `"${var}"`
123- Use functions for reusable code
124- Implement proper cleanup with trap
125- Provide helpful error messages
126- Include --help and --version options
127- Use meaningful variable names
128- Comment complex logic
129- Test with different shells when targeting POSIX
130
131## Common Patterns
132
133**Robust Script Template**
134```bash
135#!/usr/bin/env bash
136set -euo pipefail
137IFS=$'\n\t'
138
139trap 'echo "Error on line $LINENO"' ERR
140trap cleanup EXIT
141
142cleanup() {
143 rm -f "$TEMP_FILE" 2>/dev/null || true
144}
145
146main() {
147 parse_args "$@"
148 validate_environment
149 execute_task
150}
151
152main "$@"
153```
154
155**Cross-Platform Detection**
156```bash
157detect_os() {
158 case "$OSTYPE" in
159 linux*) OS="linux" ;;
160 darwin*) OS="macos" ;;
161 msys*) OS="windows" ;;
162 *) OS="unknown" ;;
163 esac
164}
165```
166
167For detailed command-line tools reference, advanced automation examples, and troubleshooting guidance, see REFERENCE.md.