Unix/Linux实战:嵌入文档使用攻略

http://tech.ddvip.com   2007年09月25日    社区交流

内容摘要:Shell编程是Unix/Linux服务器管理和维护的基本功,嵌入文档(Here Documents)技术是BASH脚本语言提供的一个特征,是用于在当前脚本内部处理重定向的一种手段……

  三、技术基础

  我们采用Red Hat Linux和Unix下面广泛使用的BASH来编写脚本。首先讲解有关Here Documents的语法基础和基本使用方法。

  3.1 语法结构

  在命令行中执行man bash,可以找到BASH手册中有关Here Documents的语法定义,其一般形式如下:

  #man bash

  Here Documents

  This type of redirection instructs the shell to read input from the

  current source until a line containing only word (with no trailing

  blanks) is seen. All of the lines read up to that point are then used

  as the standard input for a command.

  The format of here-documents is:

  <<[-]word

  here-document

  delimiter

  No parameter expansion, command substitution, arithmetic expansion, or

  pathname expansion is performed on word. If any characters in word are

  quoted, the delimiter is the result of quote removal on word, and the

  lines in the here-document are not expanded. If word is unquoted, all

  lines of the here-document are subjected to parameter expansion, com-

  mand substitution, and arithmetic expansion. In the latter case, the

  character sequence is ignored, and must be used to quote

  the characters , $, and `.

  If the redirection operator is <<-, then all leading tab characters are

  stripped from input lines and the line containing delimiter. This

  allows here-documents within shell scripts to be indented in a natural

来源:IT168    作者:靳国杰    责编:豆豆技术应用

正在加载评论...