• GNU make manual 翻译( 一百三十三)


    继续翻译

    5.3 Recipe Execution
    ====================
    
    When it is time to execute recipes to update a target, they are
    executed by invoking a new subshell for each line of the recipe, unless
    the `.ONESHELL' special target is in effect (*note Using One Shell: One
    Shell.)  (In practice, `make' may take shortcuts that do not affect the
    results.)
    
       *Please note:* this implies that setting shell variables and
    invoking shell commands such as `cd' that set a context local to each
    process will not affect the following lines in the recipe.(1)  If you
    want to use `cd' to affect the next statement, put both statements in a
    single recipe line.  Then `make' will invoke one shell to run the
    entire line, and the shell will execute the statements in sequence.
    For example:
    
         foo : bar/lose
                 cd $(@D) && gobble $(@F) > ../$@
    
    Here we use the shell AND operator (`&&') so that if the `cd' command
    fails, the script will fail without trying to invoke the `gobble'
    command in the wrong directory, which could cause problems (in this
    case it would certainly cause `../foo' to be truncated, at least).
    
       ---------- Footnotes ----------
    
       (1) On MS-DOS, the value of current working directory is *global*, so
    changing it _will_ affect the following recipe lines on those systems.

    5.3 片段执行
    ====================

    当到了执行片段去改变一个目的的时候,会通过为片段中的每一行激活一个新的子shell来执行。除非.ONESHELL 特殊目的起了效果(*note Using One Shell: One Shell)。

    *请注意:* 设置shell变量或者如cd 等命令来设置的本地上下文并不会影响后面的片段行。如果你想要用cd 来影响下一个句子,可以把所有的子句放入到一个单独的行里。 然后,make 会激活一个shell 来运行整个的行,并且shell 会按照序列运行这些句子:

    foo : bar/lose
    cd $(@D) && gobble $(@F) > ../$@

    这里我们使用 shell 的 与操作符 ,这样 如果 cd 命令失败,整个脚本将失败,不会再在错误的目录里激活 gobble 命令,不至于导致问题(在上述例子中,至少会导致 ../foo被 删除)

    ---------- 脚注 ----------

    (1) On MS-DOS, the value of current working directory is *global*, so
    changing it _will_ affect the following recipe lines on those systems.

    (1) 在 MS-DOS 系统里面,当前工作目录是 *global*, 因此改变了它的话,会影响后面的行。

    后文待续

  • 相关阅读:
    英语:真正有效的英语学习心得,把英语当母语学习!(转载)
    《2010年年度总结》
    SQL游标使用
    千万数量级分页存储过程
    关于动态创建DOM元素的问题
    MVC3 “从客户端中检测到有潜在危险的 Request.QueryString或者Request.Form 值”问题解决
    记录Ally项目的点点滴滴(一)总结
    解决session丢失问题
    转载:我的外语学习历程(如何学会十门外语)
    C#经典问题总结一
  • 原文地址:https://www.cnblogs.com/gaojian/p/2706627.html
Copyright © 2020-2023  润新知