语法:

  连接显示

选项:

  -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

05-08 15:22