bash-script-helper

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Bash-script-helper

Bash脚本助手

Instructions

说明

When writing or debugging bash scripts:
  • Always use #!/bin/bash shebang
  • Set -e (exit on error), -u (error on undefined var)
  • Use [[ ]] instead of [ ] for tests
  • Quote variables: "$variable" not $variable
  • Use $() instead of backticks
  • Check command exit codes: $?
  • Use trap for cleanup
  • Provide meaningful error messages
  • Validate input parameters
  • Argument parsing with getopts
  • Reading files line by line
  • Function definitions and calls
  • Arrays and associative arrays
  • Use set -x for trace mode
  • shellcheck for static analysis
  • Use echo/printf for debugging output
  • Avoid eval
  • Sanitize user input
  • Use mktemp for temporary files
  • Set proper file permissions
编写或调试Bash脚本时:
  • 始终使用#!/bin/bash shebang
  • 设置 -e(出错时退出)、-u(未定义变量时报错)
  • 使用 [[ ]] 而非 [ ] 进行条件测试
  • 对变量加引号:使用"$variable"而非$variable
  • 使用$()而非反引号
  • 检查命令退出码:$?
  • 使用trap进行清理操作
  • 提供有意义的错误信息
  • 验证输入参数
  • 使用getopts解析参数
  • 逐行读取文件
  • 函数定义与调用
  • 数组与关联数组
  • 使用set -x开启跟踪模式
  • 使用shellcheck进行静态分析
  • 使用echo/printf输出调试信息
  • 避免使用eval
  • 清理用户输入
  • 使用mktemp创建临时文件
  • 设置正确的文件权限

Examples

示例

Add examples of how to use this skill here.
在此添加如何使用本技能的示例。

Notes

注意事项

  • This skill was auto-generated
  • Edit this file to customize behavior
  • 本技能为自动生成
  • 编辑此文件可自定义行为