linux 中here documents 的写法

来源:互联网 发布:中国战争 知乎 编辑:程序博客网 时间:2024/06/05 02:39

     linux中关于here documents的写法,是关于cat的用法:

     #!/bin/sh
     # we have less than 3 arguments. Print the help tesxt:
    if [ $# -lt 3 ]; then
    cat << HELP
        ren -- renames a number of files using sed regular expressions
        USAGE:
                 ren 'regexp' 'replacement' files...
        EXAMPLE:
                 rename all *.HTM files in *.html:
                 ren 'HTM$' 'html' *.HTM
  HELP
        exit 0
 fi

用 cat 命令,以<<开始,后面接HELP单词,然后以HELP结束,中间的内容就是可以显示的内容。

$ ./ren

        ren -- renames a number of files using sed regular expressions
        USAGE:
                 ren 'regexp' 'replacement' files...
        EXAMPLE:
                 rename all *.HTM files in *.html:
                 ren 'HTM$' 'html' *.HTM

$