shell脚本使用技巧7--cat

cat是单词concatenate缩写

echo ‘text through stdin‘ | cat - file.txt

输出:text throgh stdin 和file.txt中的内容;

cat -s file:压缩空白行

cat -T file:标记处文件中所有的制表符为^|

cat -n line.txt :输出的内容添加行号(不会改变文件的内容的)

时间: 2024-08-26 22:42:09

shell脚本使用技巧7--cat的相关文章

shell脚本使用技巧3--调试

1.使用-x,开启shell脚本的跟踪调试功能 ex:bash -x script.sh or sh -x script.sh 2.使用set -x 和 set +x对脚本进行部分调试(输入中间的内容) #!/bin/bash #filename:debug.sh for i in {1..6}; do set -x echo $i set +x done echo "script executed" 3.固定格式生成调试信息 注:符号:告诉shell不要进行任何操作 #!/bin/b

收集的48个Shell脚本小技巧

0. shell 调试 复制代码 代码如下: sh -x somefile.sh 在somefile.sh 文件里加上set+x set-x 1. 用 && || 简化if else 复制代码 代码如下: gzip -t a.tar.gz if [[ 0 == $? ]]; then     echo "good zip" else     echo "bad zip" fi 可以简化为: 复制代码 代码如下: gzip  -t a.tar.gz &

shell脚本使用技巧2

0--stdin标准输入 1--stdout标准输出 2--stderr标准错误 重定向 echo "this is a good idea " > temp.txt temp.txt内容会被首先清空后再输入"this is a good idea" 追加 echo "this is a bad idea " >> temp.txt cat temp.txt 打印退出状态:echo $? ls + 2>out.txt 2输

shell脚本调试技巧

0.专业脚本的规范格式 函数1 函数2 main 函数 main $* 1.使用dos2unix命令转换来自windows下开发的脚本 dos2unix默认是没有安装的,可以yum 安装 # dos2unix web_jk.sh dos2unix: converting file web_jk.sh to UNIX format ... 2.使用echo 命令调试 3.使用bash命令参数调试 # sh [-nvx] scripts.sh -n    不会执行该脚本,仅查询脚本语法是否有问题,并

shell脚本使用技巧5--字符分隔

#!/bin/bash #filename:ifs.sh data="name,sex,rollon,location" oldIFS=$IFS IFS=, for item in $data; do echo Item: $item done #IFS=$oldIFS 设置IFS为,号分隔符 #!/bin/bash #filename:fenge.sh line="root:x:0:0:root:/root:bin/bash" oldIFS=$IFS IFS=&q

shell脚本小技巧

输入参数错误时,退格会出现^H,这个时候只要在脚本顶部加一条语句:stty erase ^h就可以了 #!/bin/sh stty erase ^h

shell脚本使用技巧3--函数调用

定义函数 function fname() { statements; } 或者 fname() { statements; } 传递参数给函数: fname arg1 arg2; ex: 函数参数定义: fname() { echo $1, $2; echo "[email protected]"; echo "$*"; return 0; } 检测命令是否成功执行 #!/bin/bash #filename:success_test.sh cmd="l

一个具有菜单选项的简单shell脚本

这是一个简单的shell脚本,里面包含了很多的shell脚本编写技巧,虽然脚本是从别的视频教程里面整理而来,但是对我的以后的编写shell脚本的道路有了一定的铺垫. #!/bin/bash ############# # main menu # ############# main_menu () { echo echo dis_mainmenu="CREATE MINISITE IN CHINAITLAB.COM" curdate=`date "+%Y-%m-%d %T&q

shell脚本应用(一)

1.编制我的第一个shell脚本 shell脚本是什么我来简单的说一下,shell脚本是linux系统中的一个特殊程序,他工作在操作系统内核与应用之间,充当了一个"命令解释器"的角色,负责接收用户输入的操作指令并进行解释,将需要执行的操作传递给内核执行,并输出结果. 我们来看看我自己的系统支持什么样的shell脚本种类 [[email protected] ~]# cat /etc/shells /bin/sh /bin/bash /sbin/nologin ........下边的用不