zoukankan      html  css  js  c++  java
  • Learning_the_bash_Shell_Third_Edition 15/n

    Command-Line Processing

     

    it separates lines into words, according to delimiters in the environment variable IFS; and it assigns the words to shell variables. We can think of this process as a subset of the things the shell does when processing command lines.

    cor@debian:~/shell/mar9$  echo $IFS
    
    cor@debian:~/shell/mar9$ echo "HHH"$IFS"JJJ"
    HHH JJJ
    

      

    Each line that the shell reads from the standard input or a script is called a pipeline; it contains one or more commands separated by zero or more pipe characters (|). For each pipeline it reads, the shell breaks it up into commands, sets up the I/O for the pipeline, then does the following for each command (Figure 7-1):

    1. Splits the command into tokens that are separated by the fixed set of metacharacters: SPACE, TAB, NEWLINE, ;, (, ), <, >, |, and &. Types of tokens include words, keywords, I/O redirectors, and semicolons.

    2. Checks the first token of each command to see if it is a keyword with no quotes or backslashes. If it’s an opening keyword, such as if and other control-structure openers, function, {, or (, then the command is actually a compound command. The shell sets things up  internally for the compound command, reads the next command, and starts the process again. If the keyword isn’t a compound command opener (e.g., is a control-structure “middle” like then, else, or do, an “end” like fi or done, or a logical operator), the shell signals a syntax error.

    3. Checks the first word of each command against the list of aliases. If a match is found, it substitutes the alias’s definition and goes back to Step 1; otherwise, it goes on to Step 4. This scheme allows recursive aliases (see Chapter 3). It also allows aliases for keywords to be defined, e.g., alias aslongas=while or alias procedure=function.

    4. Performs brace expansion. For example, a{b,c} becomes ab ac.

    5. Substitutes the user’s home directory ($HOME) for tilde if it is at the beginning of a word. Substitutes user’s home directory for ~user. *

    6. Performs parameter (variable) substitution for any expression that starts with a dollar sign ($).

    7. Does command substitution for any expression of the form $(string).

    8. Evaluates arithmetic expressions of the form $((string)).

    9. Takes the parts of the line that resulted from parameter, command, and arithmetic substitution and splits them into words again. This time it uses the characters in $IFS as delimiters instead of the set of metacharacters in Step 1.

    10. Performs pathname expansion, a.k.a. wildcard expansion, for any occurrences of *, ?, and [/] pairs.

    11. Uses the first word as a command by looking up its source according to the rest of the list in Chapter 4, i.e., as a function command, then as a built-in, then as a file in any of the directories in $PATH.

    12. Runs the command after setting up I/O redirection and other such things.

     command, builtin, and enable

    eval

  • 相关阅读:
    function to_timestamp(timestamp without time zone, unknown) does not exist
    Xshell连接不上Ubuntu解决方式
    怎样使用MobaXterm上传文件到远程Linux系统 MobaXterm怎么使用连接远程服务器?
    notepad++怎样删除空行
    思维脑图在线制作工具网址
    @ApiImplicitParams
    .bat批出处理文件
    主题模型及其在文本情感分析中的应用
    表达式求职JAVA(转)
    2013华为校园招聘java实现(大家水个回复啊)
  • 原文地址:https://www.cnblogs.com/winditsway/p/14509612.html
Copyright © 2011-2022 走看看