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


    继续翻译

    5.1.2 Using Variables in Recipes
    --------------------------------
    
    The other way in which `make' processes recipes is by expanding any
    variable references in them (*note Basics of Variable References:
    Reference.).  This occurs after make has finished reading all the
    makefiles and the target is determined to be out of date; so, the
    recipes for targets which are not rebuilt are never expanded.
    
       Variable and function references in recipes have identical syntax and
    semantics to references elsewhere in the makefile.  They also have the
    same quoting rules: if you want a dollar sign to appear in your recipe,
    you must double it (`$$').  For shells like the default shell, that use
    dollar signs to introduce variables, it's important to keep clear in
    your mind whether the variable you want to reference is a `make'
    variable (use a single dollar sign) or a shell variable (use two dollar
    signs).  For example:
    
         LIST = one two three
         all:
                 for i in $(LIST); do \
                     echo $$i; \
                 done
    
    results in the following command being passed to the shell:
    
         for i in one two three; do \
             echo $i; \
         done
    
    which generates the expected result:
    
         one
         two
         three

    5.1.2 在片段中使用变量
    --------------------------------

    make 处理片段的另一个方式是通过扩展任何的片段中的变量参照(*note Basics of Variable References: Reference.) 。这发生在当make 读取完毕所有的makefile并且目的被认为是过期的时候;因此,未被重新构建的目的的片段不会被展开。

    makefile中的片段的变量和函数参照有着相同的语法和语义。它们也有同样的引用规则。如果你想要你的片段中出现一个美元符号,你必须使用$$。

    对于缺省shell那样的shell, 使用美元符号来引入变量,保持头脑清醒地了解你所要使用的变量是否是 make 的变量(使用一个美元符)还是说是shell 的变量(使用两个美元符),是很重要的。例如:

    LIST = one two three
    all:
    for i in $(LIST); do \
    echo $$i; \
    done

    形成如下传递给shell的命令:

    for i in one two three; do \
    echo $i; \
    done

    得到如下的结果:

    one
    two
    three

    后文待续

  • 相关阅读:
    shell中的交互模式:expect
    hive(II)--sql考查的高频问题
    ETL工具--kettle篇(17.10.09更新)
    hive(I)--学习总结之常用技能
    ubantu上搭建hive环境
    shell实例练习+详解
    搭建hadoop、hdfs环境--ubuntu(完全分布式)
    oracle 获取一个字段的年月日
    oracle 两表更新 报错ORA-01779: 无法修改与非键值保存表对应的列
    oracle 查看表空间 添加数据文件
  • 原文地址:https://www.cnblogs.com/gaojian/p/2705654.html
Copyright © 2020-2023  润新知