语法:
连接显示
选项:
-n,显示行号。
-v,显示不可见打印符。
-E,显示“行结束符”($)。
显示行号
$ cat -n /etc/fstab 1 /dev/VolGroup00/LogVol00 / ext3 defaults 1 1 2 LABEL=/boot /boot ext3 defaults 1 2 3 tmpfs /dev/shm tmpfs defaults 0 0 4 devpts /dev/pts devpts gid=5,mode=620 0 0 5 sysfs /sys sysfs defaults 0 0 6 proc /proc proc defaults 0 0 7 /dev/VolGroup00/LogVol01 swap swap defaults 0 0
打印行末结束符
$ cat -E /etc/fstab /dev/VolGroup00/LogVol00 / ext3 defaults 1 1$ LABEL=/boot /boot ext3 defaults 1 2$ tmpfs /dev/shm tmpfs defaults 0 0$ devpts /dev/pts devpts gid=5,mode=620 0 0$ sysfs /sys sysfs defaults 0 0$ proc /proc proc defaults 0 0$ /dev/VolGroup00/LogVol01 swap swap defaults 0 0$
直接输入命令,就会进入交互模式。直到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? 1 accounting 2 cashier 3 secretary Please enter a number to select the corresponding positions. EOF echo -n "Choice: " read NUM case $NUM in 1) printf "call mr wang. number is 1124 " ;; 2) printf "call miss li. number is 1233. " ;; 3) printf "call miss ji. number is 1367. " ;; *) printf "If you want to make a lot of money, to be a seller. call 1498. " ;; 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 100, then clean-up, and leaving 30 lines. -h, --help display this help and exit E-mail bug reports to: <773805731@qq.com> EOF }
执行上边的代码,效果如下:
$ ./cat.sh Recruitment Announcement Are you ready to apply for any job? 1 accounting 2 cashier 3 secretary Please enter a number to select the corresponding positions. Choice:
从程序的输出看出,脚本里的文本格式原样在交互界面显示了。
文件结束符:
Linux: CTRL + d
Windows: CTRL + z