代码之家  ›  专栏  ›  技术社区  ›  Paul C

引用的值可以内联工作,但不能在shell脚本[duplicate]内的环境变量中工作

  •  0
  • Paul C  · 技术社区  · 9 年前

    ./configure --with-cc-opt='-O0 -g -Wno-error'
    

    但是有了 '-O0 -g -Wno-error'

    如果我用这个

    CC_OPTS="'-O0 -g -Wno-error'"
    ./configure --with-cc-opt=${CC_OPTS}
    

    就像单引号中的值被拆分一样 ./configure --with-cc-opt=-O0 -g 和 -Wno-error 作为单独的参数。

    CC_OPTS="'-O0 -g -Wno-error'"
    echo ${CC_OPTS}
    

    “-O0-g-Wno错误” ,带有右单引号。

    CC_OPTS="'-O0 -g -Wno-error'"
    echo --with-cc-opt=${CC_OPTS}
    

    --with-cc-opt='-O0 -g -Wno-error' ./配置 将它们作为单独的参数接收。

    1 回复  |  直到 9 年前
        1
  •  3
  •   that other guy    9 年前

    您需要的代码是:

    CC_OPTS="-O0 -g -Wno-error"
    ./configure --with-cc-opt="${CC_OPTS}"
    

    + 在Java字符串中,并期望它能够工作:

    String s = "1+1";
    System.out.println(1+1); // print 2
    System.out.println(s);   // prints 1+1 instead of 2
    

    你想要的是 --with-cc-opt=-O0 -g -Wno-error 作为单个参数传递。所有的引号都只是为了说服shell实现这一点,任何引号都不应该将其放入实际参数中。

    推荐文章