1、
$ cat /etc/shells
// 查看当前系统支持的Shell脚本种类
// 大多数Linux版本的默认Shell脚本 "/bin/bash"
2、
$chmod +x one.sh
// 给 one.sh 脚本,添加执行权
3、
以 "#" 开头的语句表示注释信息
4、
echo 命令用于输出字符串
5、
// 执行脚本三种方式:
$ chmod +x /root/one.sh
$ /root/one.sh
// 第一种,方式;
// 加x(执行)权限,直接在命令行输脚本路径执行
$ . one.sh
$ source one.sh
// 第二种,方式;
// 不要加执行权限,通过内部命令来加载文件中的源代码执行
$sh one.sh
// 第三种,方式;
// 指定某个Shell来解释脚本语句,“sh one.sh”是通过 /bin/bash 来解释脚本
6、
// 重定向(包含 交互设备文件:标准输入、标准输出、标准错误)
$ head /etc/passwd > 1.txt
// 重定向输出,">" 为 覆盖
$ tail /etc/passwd >> 1.txt
// 重定向输出,">>" 为 追加
$ echo 123 > pass.txt
$ useradd test
$ passwd --stdin test < pass.txt
// 重定向输入,????,不太懂 先空着
$ ls /ro 2> error.txt
$ ls /ho 2>> error.txt
// 错误重定向,"2>" 为 覆盖,"2>>" 为 追加
7、
// 管道符
$ cat /etc/passwd | grep "root"
8、
// awk 命令
01Shell_脚本_基础
最新推荐文章于 2024-08-29 20:37:16 发布