美文网首页
关于shell的EOF

关于shell的EOF

作者: CarsonCao | 来源:发表于2019-01-28 18:53 被阅读0次

    之前在执行hbase shell的时候用过这个用法,现在温习一下。
    Shell中通常将EOF与 << 结合使用,表示后续的输入作为子命令或子Shell的输入,直到遇到EOF为止,再返回到主调Shell。
    可以把EOF替换成其他东西,只要前后字符串能对应起来就可以,意思是把内容当作标准输入传给程序。

    其简单用法如下:

    <<EOF        //开始
    ....
    EOF            //结束
    

    还可以自定义,比如自定义:

    <<BBB        //开始
    ....
    BBB              //结束
    

    结合其他命令比如:

    cat << CCC
    > hello world!
    > My name is Carson!
    > CCC
    #输出:
    hello world!
    My name is Carson!
    

    执行mysql命令:

    mysql -uroot -proot my_db <<EOF
    > show tables;
    > select count(*) from test;
    > EOF
    

    执行hbase shell:

    exec $HBASE_HOME/bin/hbase shell <<EOF 
    disable 't_abc'
    drop 't_abc'
    create 't_abc', 'info'
     
    EOF
    

    最后我们看一下flume启动命令里的帮助文档是如何显示的:

    display_help() {
      cat <<EOF
    Usage: $0 <command> [options]...
    
    commands:
      help                      display this help text
      agent                     run a Flume agent
      avro-client               run an avro Flume client
      version                   show Flume version info
    
    global options:
      --conf,-c <conf>          use configs in <conf> directory
      --classpath,-C <cp>       append to the classpath
      --dryrun,-d               do not actually start Flume, just print the command
      --plugins-path <dirs>     colon-separated list of plugins.d directories. See the
                                plugins.d section in the user guide for more details.
                                Default: \$FLUME_HOME/plugins.d
      -Dproperty=value          sets a Java system property value
      -Xproperty=value          sets a Java -X option
    
    agent options:
      --name,-n <name>          the name of this agent (required)
      --conf-file,-f <file>     specify a config file (required if -z missing)
      --zkConnString,-z <str>   specify the ZooKeeper connection to use (required if -f missing)
      --zkBasePath,-p <path>    specify the base path in ZooKeeper for agent configs
      --no-reload-conf          do not reload config file if changed
      --help,-h                 display help text
    
    avro-client options:
      --rpcProps,-P <file>   RPC client properties file with server connection params
      --host,-H <host>       hostname to which events will be sent
      --port,-p <port>       port of the avro source
      --dirname <dir>        directory to stream to avro source
      --filename,-F <file>   text file to stream to avro source (default: std input)
      --headerFile,-R <file> File containing event headers as key/value pairs on each new line
      --help,-h              display help text
    
      Either --rpcProps or both --host and --port must be specified.
    
    Note that if <conf> directory is specified, then it is always included first
    in the classpath.
    
    EOF
    }
    

    相关文章

      网友评论

          本文标题:关于shell的EOF

          本文链接:https://www.haomeiwen.com/subject/kcczjqtx.html