zoukankan      html  css  js  c++  java
  • cat & 文件结束符

    语法:

      连接显示

    选项:

      -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

     

    一切代码都是为了生活,一切生活都是调剂
  • 相关阅读:
    Html-Css 从入门到放弃(一)基础知识
    PHP7 学习笔记(十)会话控制
    Redis模块学习笔记(一)RediSearch简单使用
    PHP7 学习笔记(九)phpsize动态编译openssl扩展 (微信公众平台)
    Git与GitHub学习笔记(五)一次提交失败的记录
    PHP7 学习笔记(八)JetBrains PhpStorm 2017.1 x64 MySQL数据库管理工具的使用
    PHP7 学习笔记(七)如何使用zephir编译一个扩展记录
    阿里云(四)Linux 实例常用内核网络参数介绍与常见问题处理
    阿里云(三)安全组
    流媒体技术学习笔记之(十七)FFmpeg 3.3《希尔伯特》-新版本的亮点
  • 原文地址:https://www.cnblogs.com/argor/p/7910336.html
Copyright © 2011-2022 走看看