Command that exits with zero status (not /bin/true)?
I've got a Makefile that runs a tool that takes a little while; it allows me to replace the command used:
make TOOL=alternative-tool
I'd like to skip that step in the Makefile, so I'm looking for a command that exits with status 0, and that has negligible side-effects.
Obviously, I could just use true
, but that's kinda confusing:
make TOOL=true
That reads as if I want to run the tool, but I don't.
Is there a default-installed executable that isn't /bin/true
that exits with status 0, and that has a catchy and easy to type name?
Solution 1:
Even though you've asked for something that is "not /bin/true
", replacing true
with the full name /bin/true
to show that it is the true
program rather than some other meaning of "true" is probably the best solution.
Your concern is that the true
in
make TOOL=true
appears to be something other than a command name. But if you write
make TOOL=/bin/true
then that is unambiguously a command. Somebody might misread TOOL=true
to mean that some other tool somewhere is intended, but no such misreading of TOOL=/bin/true
is likely.
I am unsure as to when :
, which is a shell builtin but not an external command, will work. Henning Makholm has reported that it appears to work. But I think it does not work in all situations, and you found that it did not work for you.
As for a shell alias, you cannot use that because alias expansion is not performed in the arguments you pass to a command, nor do makefiles make any use of previously defined shell aliases. Even if make
runs your commands in a new shell, that shell will not have the alias (and would not use it even if it did have it, because it would be a noninteractive shell, where alias expansion is not automatically enabled).
Solution 2:
While I agree that using the full path to true
would be the best solution, I'd like to note what's probably by far the most common way to avoid real command execution: sticking an echo
in front of it. So:
make TOOL=echo
Solution 3:
You can always make your own command that does nothing but return a zero exit status. Some options:
an appropriately named symbolic link to
/bin/true
an empty shell script
-
a nearly empty C program:
int main() { return 0; }