简体   繁体   中英

GCC, what does -&& mean on the command line?

I execute a command like this

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

and can get the result :1. but I can not find out what the -&& means,even after search man page and google!.and I try to execute it without the -&& option.it will be error like this:

./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

......

Who knows the option means?

-&& is interpreted by the shell not as a single token, but as two separate tokens: - and && . The - token has no special meaning to the shell and is passed as an argument to gcc , which interprets it as an instruction to read the source from the standard input. && is the shell operator that connects two commands in an and clause: A && B will execute B ( a.out ) only if A ( echo ... | gcc ... ) has finished successfully.

The point of using gcc ... && ./a.out instead of the simpler gcc ...; ./a.out gcc ...; ./a.out is to run a.out only if the compilation has been successful, preventing a stale a.out from being executed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM