1. shell 脚本第一行
shell 脚本中 第一行 #!/usr/bin/bash
作用用来 指定 该脚本的解释器
查看当前有哪些shell:
cat /etc/shells
2. shell 脚本中嵌套其他脚本
#!/bin/bash
echo "hello shell"
/usr/bin/python <<-EOF
# python 代码
print("hello python")
EOF
3. shell的执行方式
. 执行
source 执行
这两种方式执行的脚本中的变量 可以在当前shell 中直接使用,属于在当前shell中执行
其他情况基本使用 sub shell 方式执行
4. loginshell 和nologinshell
loginshell 登录的shell
命令:su - tom # 登录tom 用户的shell
nologinshell 没有登录的shell
命令: su tom # 使用的是 没有登录的shell
用户登录时执行:
# 系统级
/etc/profile
/etc/bashrc
# 用户级
~/.bash_profile
~/.bashrc
# 用户退出执行
# 用户级
~/.bash_logout
~/.bash_history
# login shell 执行
/etc/profile
/etc/bashrc
~/.bash_profile
~/.bashrc
# nologin shell 执行
/etc/bashrc
~/.bashrc
5. 历史命令
1. 上下键可以 查看历史命令
2. !number 执行 历史该编号命令
3. !string 比如 !da 执行 da开始的命令
4. !! 执行上一条命令