美文网首页
关于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

    shell中通常将EOF与 << 结合使用,表示后续的输入作为子命令或子Shell的输入,直到遇到EOF为止,再返...

  • 关于shell的EOF

    之前在执行hbase shell的时候用过这个用法,现在温习一下。Shell中通常将EOF与 << 结合使用,表示...

  • shell中的EOF用法

    1、EOF Shell中通常将EOF与 << 结合使用,表示后续的输入作为子命令或子Shell的输入,直到遇到EO...

  • 脚本改写总结

    1.cat EOF cat << EOF后的文本为标准输入,不需要考虑shell语法缩进,直接按实际缩进编写 EO...

  • linux shell脚本EOF

    一般使用 echo "内容" > test.sh 为test.sh 填充内容echo "内容" >> test.s...

  • 上机实验(03次)

    快速排序与折半查找 readme 关于本程序中的EOF说明:由于程序包含标准输入,以EOF结束循环。win下EOF...

  • Linux Shell中EOF的妙用

    笔者最近遇到几起在Shell中使用EOF来定义一块执行脚本,终于可以大大减少代码量和增强逻辑性,现在将其总结分享出...

  • shell脚本编程

    变量 1、定义变量时,变量名不加符号即可。 shell注释 1、以#开头的行就是注释。2、多行注释。 EOF也可以...

  • shell学习笔记(二)

    1.EOF的用法 EOF:end of file 文件的结尾. EOF通常与<<结合使用,<

  • 命令行中打开文件后执行命令

    << EOF 是执行一命令,命令从<

网友评论

      本文标题:关于shell的EOF

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