bash-scripting
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBash Scripting Workflow
Bash脚本编写工作流
Overview
概述
Specialized workflow for creating robust, production-ready bash scripts with defensive programming patterns, comprehensive error handling, and automated testing.
这是一个专门的工作流,用于创建健壮的、可投入生产的bash脚本,涵盖防御性编程模式、全面的错误处理和自动化测试。
When to Use This Workflow
何时使用此工作流
Use this workflow when:
- Creating automation scripts
- Writing system administration tools
- Building deployment scripts
- Developing backup solutions
- Creating CI/CD scripts
在以下场景使用此工作流:
- 创建自动化脚本时
- 编写系统管理工具时
- 构建部署脚本时
- 开发备份解决方案时
- 创建CI/CD脚本时
Workflow Phases
工作流阶段
Phase 1: Script Design
阶段1:脚本设计
Skills to Invoke
要调用的技能
- - Professional scripting
bash-pro - - Defensive patterns
bash-defensive-patterns
- - 专业脚本编写
bash-pro - - 防御性编程模式
bash-defensive-patterns
Actions
操作步骤
- Define script purpose
- Identify inputs/outputs
- Plan error handling
- Design logging strategy
- Document requirements
- 定义脚本用途
- 确定输入/输出
- 规划错误处理机制
- 设计日志策略
- 记录需求
Copy-Paste Prompts
可复制粘贴的提示语
Use @bash-pro to design production-ready bash scriptUse @bash-pro to design production-ready bash scriptPhase 2: Script Structure
阶段2:脚本结构
Skills to Invoke
要调用的技能
- - Script structure
bash-pro - - Safety patterns
bash-defensive-patterns
- - 脚本结构设计
bash-pro - - 安全编程模式
bash-defensive-patterns
Actions
操作步骤
- Add shebang and strict mode
- Create usage function
- Implement argument parsing
- Set up logging
- Add cleanup handlers
- 添加shebang和严格模式
- 创建使用说明函数
- 实现参数解析
- 配置日志功能
- 添加清理处理程序
Copy-Paste Prompts
可复制粘贴的提示语
Use @bash-defensive-patterns to implement strict mode and error handlingUse @bash-defensive-patterns to implement strict mode and error handlingPhase 3: Core Implementation
阶段3:核心实现
Skills to Invoke
要调用的技能
- - Linux commands
bash-linux - - Shell scripting
linux-shell-scripting
- - Linux命令使用
bash-linux - - Shell脚本编写
linux-shell-scripting
Actions
操作步骤
- Implement main functions
- Add input validation
- Create helper functions
- Handle edge cases
- Add progress indicators
- 实现主函数
- 添加输入验证
- 创建辅助函数
- 处理边界情况
- 添加进度指示器
Copy-Paste Prompts
可复制粘贴的提示语
Use @bash-linux to implement system commandsUse @bash-linux to implement system commandsPhase 4: Error Handling
阶段4:错误处理
Skills to Invoke
要调用的技能
- - Error handling
bash-defensive-patterns - - Error patterns
error-handling-patterns
- - 错误处理
bash-defensive-patterns - - 错误处理模式
error-handling-patterns
Actions
操作步骤
- Add trap handlers
- Implement retry logic
- Create error messages
- Set up exit codes
- Add rollback capability
- 添加陷阱处理程序
- 实现重试逻辑
- 创建错误提示信息
- 设置退出码
- 添加回滚能力
Copy-Paste Prompts
可复制粘贴的提示语
Use @bash-defensive-patterns to add comprehensive error handlingUse @bash-defensive-patterns to add comprehensive error handlingPhase 5: Logging
阶段5:日志管理
Skills to Invoke
要调用的技能
- - Logging patterns
bash-pro
- - 日志记录模式
bash-pro
Actions
操作步骤
- Create logging function
- Add log levels
- Implement timestamps
- Configure log rotation
- Add debug mode
- 创建日志函数
- 添加日志级别
- 实现时间戳
- 配置日志轮转
- 添加调试模式
Copy-Paste Prompts
可复制粘贴的提示语
Use @bash-pro to implement structured loggingUse @bash-pro to implement structured loggingPhase 6: Testing
阶段6:测试
Skills to Invoke
要调用的技能
- - Bats testing
bats-testing-patterns - - ShellCheck
shellcheck-configuration
- - Bats测试
bats-testing-patterns - - ShellCheck
shellcheck-configuration
Actions
操作步骤
- Write Bats tests
- Run ShellCheck
- Test edge cases
- Verify error handling
- Test with different inputs
- 编写Bats测试用例
- 运行ShellCheck检查
- 测试边界情况
- 验证错误处理机制
- 使用不同输入测试
Copy-Paste Prompts
可复制粘贴的提示语
Use @bats-testing-patterns to write script testsUse @shellcheck-configuration to lint bash scriptUse @bats-testing-patterns to write script testsUse @shellcheck-configuration to lint bash scriptPhase 7: Documentation
阶段7:文档编写
Skills to Invoke
要调用的技能
- - Documentation
documentation-templates
- - 文档模板
documentation-templates
Actions
操作步骤
- Add script header
- Document functions
- Create usage examples
- List dependencies
- Add troubleshooting section
- 添加脚本头部信息
- 记录函数说明
- 创建使用示例
- 列出依赖项
- 添加故障排除章节
Copy-Paste Prompts
可复制粘贴的提示语
Use @documentation-templates to document bash scriptUse @documentation-templates to document bash scriptScript Template
脚本模板
bash
#!/usr/bin/env bash
set -euo pipefail
readonly SCRIPT_NAME=$(basename "$0")
readonly SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"; }
error() { log "ERROR: $*" >&2; exit 1; }
usage() { cat <<EOF
Usage: $SCRIPT_NAME [OPTIONS]
Options:
-h, --help Show help
-v, --verbose Verbose output
EOF
}
main() {
log "Script started"
# Implementation
log "Script completed"
}
main "$@"bash
#!/usr/bin/env bash
set -euo pipefail
readonly SCRIPT_NAME=$(basename "$0")
readonly SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"; }
error() { log "ERROR: $*" >&2; exit 1; }
usage() { cat <<EOF
Usage: $SCRIPT_NAME [OPTIONS]
Options:
-h, --help Show help
-v, --verbose Verbose output
EOF
}
main() {
log "Script started"
# Implementation
log "Script completed"
}
main "$@"Quality Gates
质量检查项
- ShellCheck passes
- Bats tests pass
- Error handling works
- Logging functional
- Documentation complete
- ShellCheck检查通过
- Bats测试用例通过
- 错误处理机制正常工作
- 日志功能正常
- 文档完整
Related Workflow Bundles
相关工作流包
- - OS scripting
os-scripting - - Linux troubleshooting
linux-troubleshooting - - DevOps automation
cloud-devops
- - 操作系统脚本编写
os-scripting - - Linux故障排查
linux-troubleshooting - - DevOps自动化
cloud-devops