huangfen2002 发表于 2018-8-16 13:07:55

Shell之Here Document

  请移步https://higoge.github.io/,所有下载资料在那个博客都能找到。谢谢。
  --------------------------------------------------------------------
  最近使用Shell编程编辑文件的时候,学习到了Here Document。感觉不错,分享给大家。
  Here Document是已“ 文件。但是要删除一行怎么办?Here Document就搞定了。
  经Jeremiah测试,在Here Document中使用vi是不行的。替代方法是使用ed命令。在命令行执行以下:
  $ touch base.txt
  $ ed base.txt
  a
  this is line1.
  this is line2.
  this is line3.
  this is line4.
  .
  wq
  先新建一个文件base.txt,然后ed这个文件,输入a表示最后追加,输入了四行文字。.表示结束输入。wq表示保存退出。
  那我们再用ed命令,在shell脚本里面对这个文件再次进行操作。如下。
  #!/bin/sh
  ed base.txtuse mysql
  Reading table information for completion of table and column names
  You can turn off this feature to get a quicker startup with -A
  mysql> select * from user;
  mysql> exit
  Bye
  如果我们要用shell脚本访问,则可以编写如下的脚本。
  #!/bin/sh
  mysql -u root
页: [1]
查看完整版本: Shell之Here Document