1

我执行这样的命令

echo 'int main(){printf("%lu\n",sizeof(void));}' | gcc -xc  -w -&& ./a.out

并可以得到结果:1。但我无法找出 -&& 的含义,即使在搜索手册页和谷歌之后!。我尝试在没有 -&& 选项的情况下执行它。这将是这样的错误:

./a.out:1: error: stray ‘\317’ in program
./a.out:1: error: stray ‘\372’ in program
./a.out:1: error: stray ‘\355’ in program
./a.out:1: error: stray ‘\376’ in program
./a.out:1: error: stray ‘\7’ in program
./a.out:1: error: stray ‘\1’ in program
./a.out:1: error: stray ‘\3’ in program
./a.out:1: error: stray ‘\200’ in program
./a.out:1: error: stray ‘\2’ in program
./a.out:1: error: stray ‘\16’ in program
./a.out:1: error: expected identifier or ‘(’ before numeric constant
./a.out:1: error: stray ‘\6’ in program
./a.out:1: error: stray ‘\205’ in program
./a.out:1: error: stray ‘\31’ in program
./a.out:1: error: stray ‘\1’ in program
./a.out:1: error: stray ‘\31’ in program
./a.out:1: error: stray ‘\2’ in program

……

谁知道选项是什么意思?

4

1 回答 1

13

-&&被 shell 解释为不是单个标记,而是两个单独的标记:-&&. 标记对-shell 没有特殊意义,gcc它作为参数传递给 ,它解释为从标准输入读取源的指令。是在and子句&&中连接两个命令的 shell 运算符:仅当( ) 成功完成时才会执行( )。A && BBa.outAecho ... | gcc ...

使用gcc ... && ./a.out而不是更简单的要点是仅在编译成功时才gcc ...; ./a.out运行,从而防止执行过时的文件。a.outa.out

于 2013-07-18T06:43:04.477 回答