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