shell脚本基础:
1、 cat > test 建立文件使用cat将终端输入写到文件中
who | wc -l 程序内容(统计在线人数)
^D ctrl+d end of file
chmod +x test 给文件授予执行权限
./test 执行文件
2、tr语法:转换字符
tr [options] sourc-list repalce-list
options:
-c:
-C:
-d: 删除
-s: 去重
3、重定向符号
< 右边作为左边的输入
> 左边作为右边的输入(会覆盖目标数据)
>> 左边作为右边的输入(不会覆盖目标数据)
4、tr -d '\r' < test.txt
tr先将test.txt中的回车删掉,再将内容输出
tr -d '\r' < test.txt > test1.txt
tr先将test.txt中的回车删掉,再将test.txt中的内容写入到test1.txt中
5、for f int test.txt
do
tr -d '\r' < $f >> test1.txt
done
将test.txt中的内容追加到test1.txt中
7、管道 |:管道左边作为右边的输入
tr -d '\r' < test.txt | sort > test1.txt
将test.txt中的内容排序然后输出到test1.txt中
8、跟踪脚本运行
sh -x program(所执行的命令)
或在脚本中使用set -x 打开命令跟踪 set +x 关闭命令跟踪
1、 cat > test 建立文件使用cat将终端输入写到文件中
who | wc -l 程序内容(统计在线人数)
^D ctrl+d end of file
chmod +x test 给文件授予执行权限
./test 执行文件
2、tr语法:转换字符
tr [options] sourc-list repalce-list
options:
-c:
-C:
-d: 删除
-s: 去重
3、重定向符号
< 右边作为左边的输入
> 左边作为右边的输入(会覆盖目标数据)
>> 左边作为右边的输入(不会覆盖目标数据)
4、tr -d '\r' < test.txt
tr先将test.txt中的回车删掉,再将内容输出
tr -d '\r' < test.txt > test1.txt
tr先将test.txt中的回车删掉,再将test.txt中的内容写入到test1.txt中
5、for f int test.txt
do
tr -d '\r' < $f >> test1.txt
done
将test.txt中的内容追加到test1.txt中
7、管道 |:管道左边作为右边的输入
tr -d '\r' < test.txt | sort > test1.txt
将test.txt中的内容排序然后输出到test1.txt中
8、跟踪脚本运行
sh -x program(所执行的命令)
或在脚本中使用set -x 打开命令跟踪 set +x 关闭命令跟踪