1、脚本传递参数测试
#!/bin/bash
#test.sh
#test pass parameters
#by wzs 20171021
echo "$# parameters"
echo "$@"
运行脚本如下:
book@wzs:~/work/tq210/shell$ ./test.sh a "b c d"
2 parameters
a b c d
2、管道
cmd1 | cmd2 , 把cmd1的标准输出与cmd2的标准输入相连
没有程序数量限制,可以无限增加管道,如:
book@wzs:~/work/tq210/shell$ head -5 /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
book@wzs:~/work/tq210/shell$
book@wzs:~/work/tq210/shell$ head -5 /etc/passwd | grep bash
root:x:0:0:root:/root:/bin/bash
无符号整数的句柄,打开现有文件或新建文件时,内核都会返回一个文件描述符
读写文件时需要指定文件描述符
标准输入的文件描述符是0
标准输出的文件描述符是2
标准错误的文件描述符是2
4、重定向
重定向标准输出:> 或 1>
book@wzs:~/work/tq210/shell$ cat test.sh > 1.text
book@wzs:~/work/tq210/shell$ cat test.sh 1> 1.text
重定向标准错误:2>
重定向标准输入:0<
重定向标准输出和标准错误:&>
5、特殊文件
/dev/null:所有写入/dev/null的信息都消失
/dev/zero:创建一个指定长度,并且初始化为空的文件