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