cat & 文件结束符
语法:
连接显示
选项:
-n,显示行号。
-v,显示不可见打印符。
-E,显示“行结束符”($)。
显示行号
$ cat -n /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults
LABEL=/boot /boot ext3 defaults
tmpfs /dev/shm tmpfs defaults
devpts /dev/pts devpts gid=,mode=
sysfs /sys sysfs defaults
proc /proc proc defaults
/dev/VolGroup00/LogVol01 swap swap defaults
打印行末结束符
$ cat -E /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults $
LABEL=/boot /boot ext3 defaults $
tmpfs /dev/shm tmpfs defaults $
devpts /dev/pts devpts gid=,mode= $
sysfs /sys sysfs defaults $
proc /proc proc defaults $
/dev/VolGroup00/LogVol01 swap swap defaults $
直接输入命令,就会进入交互模式。直到cat接到一个“文件结束符”时停止交互。
$ cat
hello
hello
are you busy?
are you busy?
$
重写程序(case语句的第一个例子“找工作时联系人信息”),使用“文件结束符”,格式化显示交互信息:
#!/bin/bash cat << EOF
Recruitment Announcement
Are you ready to apply for any job?
accounting
cashier
secretary
Please enter a number to select the corresponding positions.
EOF echo -n "Choice: "
read NUM
case $NUM in
)
printf "call mr wang. number is 1124\n"
;;
)
printf "call miss li. number is 1233.\n"
;;
)
printf "call miss ji. number is 1367.\n"
;;
*)
printf "If you want to make a lot of money, to be a seller. call 1498.\n"
;;
esac
打印程序的提示信息:
display_help () {
cat << EOF
Usage: findTom [OPTION]
View the tomcat information.
View the home directory of the tomcat program running on the system, and
the project path.
Mandatory arguments to long option are mandatory for short options too.
-r, --read
view the previously running tomcat information.
-v, --version
view the version
--clear
when the number of row is greater than , then clean-up, and leaving lines.
-h, --help
display this help and exit
E-mail bug reports to: <@qq.com>
EOF
}
执行上边的代码,效果如下:
$ ./cat.sh
Recruitment Announcement
Are you ready to apply for any job?
accounting
cashier
secretary
Please enter a number to select the corresponding positions.
Choice:
从程序的输出看出,脚本里的文本格式原样在交互界面显示了。
文件结束符:
Linux: CTRL + d
Windows: CTRL + z
cat & 文件结束符的更多相关文章
- linux下文件结束符
linux下文件结束符,我试过了所有的linux,发现其文件的结束符都是以0a即LF结束的,这个是操作系统规定的,windows下是\r\n符结束,希望可以帮助大家. -------------转:来 ...
- 文件结束符和C\C++读取文件方式
http://www.cnblogs.com/cvbnm/articles/2003056.html 约定编译器为 gcc2/x86: 所以 char, unsigned char 为 8 位, in ...
- Windows环境下C++中关于文件结束符的问题
参考资料:http://www.cnblogs.com/day-dayup/p/3572374.html 一.前言 在不同的OS环境下,程序中对应的文件结束符有所不一样,根据<C++ Prime ...
- 关于windows下的文件结束符
在<c++ primer>中有说,在windows中文件结束符为:ctrl+z,在Linux中为:ctrl+D. 但是在while(cin>>s)的语句运行中,需要两次的^Z, ...
- linux 下vim文件乱码 cat文件正常处理方法
linux 下vim文件乱码 cat文件正常处理方法 服务器支持中文字符集,cat和其他查看文件命令现在正常,vim还是出现了中文乱码问题, 1.查看文件编码格式 vim 文件 :set fileen ...
- 关于文件结束符EOF
EOF 是 End Of File 的缩写. 在 C 语言中,它是在标准库中定义的一个宏. 人们经常误认为 EOF 是从文件中读取的一个字符(牢记).其实,EOF 不是一个字符,它被定义为是 int ...
- linux cat 文件操作
简略版: cat主要有三大功能:1.一次显示整个文件.$ cat filename2.从键盘创建一个文件.$ cat > filename 只能创建新文件,不能编辑已有文件.3.将几个文 ...
- linux cat 文件编码
test.log是utf-16的编码 cat test.log会报错 但是我们可以cat的时候指定编码格式 iconv -f 文件编码 -t 终端编码 input.log iconv -f utf-1 ...
- Linux cat文件正常,vim文件乱码
cat: vim: 1.临时解决 vim 文件后,命令模式下执行: :set encoding=utf-8 2.永久解决 vi 配置文件路径:/etc/virc vim 配置文件路径:/etc/ ...
随机推荐
- c++ 函数中的部分代码执行一次
编程时有时需要将一段代码中的某一块只执行一次: #include<iostream> using namespace std; int fun1(int a) { static bool ...
- kettle判断是否是数据首行(第一行)
可以用组件:分析查询(Analytic Query) 后面可以通过判断pre_id 是否为空值(null)判断.
- java线程大全一讲通
Java线程:概念与原理 一.操作系统中线程和进程的概念 现在的操作系统是多任务操作系统.多线程是实现多任务的一种方式. 进程是指一个内存中运行的应用程序,每个进程都有自己独立的一块内存空间,一个进程 ...
- js copy数组 对象
js copy数组 slice concat 浅拷贝 copy 对象 Object.assign({},obj); es6 ie要用babel转 暴力copy 用JSON.parse(JSON. ...
- 测试教程网.unittest教程.4. 实例: 读取测试数据并测试弱密码
From: http://www.testclass.net/pyunit/test_example_2/ 背景 接上一节的弱密码例子,我们的用例尽管运行的不错,但还是有点问题. 假如我们需要增加一些 ...
- Unable to load native-hadoop library for your platform... using builtin-java classes where applicable(四十四)
问题描述: Unable to load native-hadoop library for your platform... using builtin-java classes where app ...
- [C#][EF] 添加表添加不进来
确认此表有没有主键,没有主键时就会这样.
- [VS2013]发布网站时修改配置文件
本文来自:https://msdn.microsoft.com/en-us/library/ee942158.aspx#encrypt_webconfig Web Deployment FAQ for ...
- BOF、EOF 属性
BOF.EOF 属性 BOF 指示当前记录位置位于 Recordset 对象的第一个记录之前. EOF 指示当前记录位置位于 Recordset 对象的最后一个记录之后. 返回值 BOF 和 EOF ...
- 廖雪峰Java-3流程控制-7for循环
for循环 for循环使用计数器实现循环 for循环条件需要设置:计数器初始值:循环前检测条件:每次循环后如何更新计数器 计数器变量通常命名为i int[] ns = {1,4,9,16,25}; f ...