bashninja

what the point of ": &&" command


I use ninja build system and i got some errors in the build process.

Ninja prints the command that raised the error and it seems that every commands look like this:

: && /usr/bin/g++ -Wno-attributes -pthread -g3 -ggdb3 ...

What the point of starting the command with : && ? I understand that it lokks like if true then cmd but I don't get the point.


Solution

  • One possibility is that this Bash script is being generated by some program, and there are some conditions under which the : would have been a real command instead. It may be simpler for that program to always emit COMMAND && ... at this point in its output, with the command being : when there's nothing to do there, than for the program to emit the COMMAND && part only when needed. (In other words, this may just be a weird artifact of the logic that happened to generate the command.)

    Edited to add: Another possibility — also specific to generated code — is that the generating program is building a dynamic list of commands that need to be run in the form COMMAND1 && COMMAND2 && COMMAND3. It can be convenient, in that case, for it to start with : and then add each command by appending && COMMAND, rather than having to keep track of whether a given command is the first.