shell-scripting
SolidBash Shell 脚本编写
AI & Automation 1 stars
0 forks Updated yesterday Apache-2.0
Install
Quality Score: 79/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
Skill Content
# Shell 脚本编写
## 概述
Bash 脚本编写、调试、最佳实践等技能。
## 基础语法
### 脚本结构
```bash
#!/bin/bash
# 脚本描述
# Author: name
# Date: 2024-01-01
set -euo pipefail # 严格模式
# 变量定义
VAR="value"
readonly CONST="constant"
# 主逻辑
main() {
echo "Hello, World!"
}
main "$@"
```
### 变量
```bash
# 定义变量
name="value"
name='literal value' # 不解析变量
# 使用变量
echo $name
echo ${name}
echo "${name}_suffix"
# 默认值
${var:-default} # 未设置时使用默认值
${var:=default} # 未设置时赋值并使用
${var:+value} # 已设置时使用 value
${var:?error message} # 未设置时报错
# 字符串操作
${#var} # 长度
${var:0:5} # 子串
${var#pattern} # 删除前缀
${var%pattern} # 删除后缀
${var/old/new} # 替换
```
### 数组
```bash
# 定义数组
arr=(a b c d)
arr[0]="first"
# 访问数组
${arr[0]} # 第一个元素
${arr[@]} # 所有元素
${#arr[@]} # 数组长度
${!arr[@]} # 所有索引
# 遍历数组
for item in "${arr[@]}"; do
echo "$item"
done
```
## 流程控制
### 条件判断
```bash
# if 语句
if [[ condition ]]; then
commands
elif [[ condition ]]; then
commands
else
commands
fi
# 条件表达式
[[ -f file ]] # 文件存在
[[ -d dir ]] # 目录存在
[[ -z "$var" ]] # 变量为空
[[ -n "$var" ]] # 变量非空
[[ "$a" == "$b" ]] # 字符串相等
[[ "$a" != "$b" ]] ...
Details
- Author
- ryukyagamilight
- Repository
- ryukyagamilight/terminal-skills
- Created
- 5 months ago
- Last Updated
- yesterday
- Language
- N/A
- License
- Apache-2.0
Integrates with
Similar Skills
Semantically similar based on skill content — not just same category
AI & Automation Listed
sota-shell-scripting
State-of-the-art shell scripting (bash-focused, defensive) for writing and auditing shell scripts, CI scripts, init/deploy scripts, container entrypoints, and Makefile recipes. Use when the task involves creating, modifying, reviewing, or hardening any shell code — trigger keywords: bash, shell script, sh, zsh, shellcheck, shfmt, CI script, Makefile shell, entrypoint script, set -euo pipefail, dotfiles, install script, cron job, wrapper script.
8 Updated 3 days ago
martinholovsky Testing & QA Listed
how-to-test
完成代码改动后,给出有实际信号的验证步骤;只验证行为、集成、类型、构建或真实副作用,避免低价值脚本和实现细节断言
2 Updated today
beixiyo AI & Automation Listed
bash-script
Use when writing a Bash script. Covers the template, conventions, and required patterns.
1 Updated today
LandonSchropp