This commit is contained in:
2021-11-14 15:52:46 +08:00
parent 915c231124
commit 1e344dc204
112 changed files with 1039 additions and 1039 deletions

View File

@@ -6,7 +6,7 @@ tags: ["shell"]
categories: ["shell"]
---
# BASH 脚本的 $ 参数
## BASH 脚本的 $ 参数
- $$ #shell 本身 PID
- $! #shell 最后执行的后台PID
- $? #shell 结束代码
@@ -16,7 +16,7 @@ categories: ["shell"]
- $0 #shell 脚本名
- $1...$n #shell 位置参数
# BASH 字符串处理
## BASH 字符串处理
```bash
# 字符串 str 长度
${#str}
@@ -82,7 +82,7 @@ categories: ["shell"]
${var:?word}
```
# BASH 数组
## BASH 数组
```bash
# 定义数组,有三种方式
declare -a array
@@ -111,7 +111,7 @@ categories: ["shell"]
array[3]=""
```
# BASH 字典
## BASH 字典
```bash
# 定义字典
declare -A dict
@@ -138,7 +138,7 @@ categories: ["shell"]
unset dict['k1']
```
# 终端环境变量 PS1 参数
## 终端环境变量 PS1 参数
- \d 日期格式为weekday month date例如"Mon Aug 1"
- \H 完整的主机名称
- \h 仅取主机的第一个名字
@@ -153,7 +153,7 @@ categories: ["shell"]
- \$ 提示字符root 下提示符是 #,普通用户是 $
- \\[\e[i;j;km\\] \\[\e[0m\\] 建议PS1使用这种颜色控制字符
# 终端颜色 \033[F;Bm 控制编码
## 终端颜色 \033[F;Bm 控制编码
- F30 B40 黑色
- F31 B41 红色
- F32 B42 绿色
@@ -163,7 +163,7 @@ categories: ["shell"]
- F36 B46 青蓝色
- F37 B47 白色
# 终端光标位置
## 终端光标位置
- \033[K 清除从光标到行尾的内容
- \033[s 保存光标位置
- \033[u 恢复光标位置
@@ -182,11 +182,11 @@ categories: ["shell"]
- \033[?25h 显示光标
- \033[y;xH 设置光标位置
# 解析迅雷链接
## 解析迅雷链接
- echo 迅雷专用地址(去掉头 thunder://)|base64 -d
- 去掉头部 AA 和尾部 ZZ
# expect 自动输入密码
## expect 自动输入密码
```bash
expect<<END
spawn ssh $DEST_HOST "REMOTE_COMMAND"
@@ -198,7 +198,7 @@ categories: ["shell"]
END
```
# 普通用户(username)免密 sudo
## 普通用户(username)免密 sudo
```bash
echo "username ALL = (root) NOPASSWD:ALL" >> /etc/sudoers
# 或
@@ -206,7 +206,7 @@ categories: ["shell"]
chmod 0400 /etc/sudoers.d/username
```
# 用户登陆操作记录
## 用户登陆操作记录
- 创建日志共存目录
```bash
mkdir /var/log/user_history -p