1

My Makefile:

all: ...(other rules) clean

clean:
    rm $(find . -type f -executable)

When I delete clean rule from the above Makefile everything works as expected. After adding, make (also make clean) command results in:

rm 
rm: missing operand
Try 'rm --help' for more information.
make: *** [Makefile:46: clean] Error 1

What causes problem here and how can I solve?

2
  • 3
    Is there a reason not to use find . -type f -executable -delete? Also note that $ introduces the expansion of a makefile variable.
    – Kusalananda
    Sep 19, 2021 at 10:14
  • @Kusalananda actually I'm not aware of -delete opt in find. Do you say that $ has a special meaning in Makefile and there is no workaround for this? Sep 19, 2021 at 10:21

1 Answer 1

4

You want to run the command

rm $(find . -type f -executable)

to let the shell do the command substitution. To do this you need to write

clean:
        rm $$(find . -type f -executable)

with the dollar doubled. If your version of find supports it, it would be better to use

clean:
        find . -type f -executable -delete

as it avoids problems with characters like spaces in the output of find if you have them in your filenames.

1
  • 1
    Note also that the variant with the command substitution is severely limited in what filenames it would safely work with. An executable file with a space in its name would be treated as two files, and a file simply called * would cause all files to be deleted.
    – Kusalananda
    Sep 19, 2021 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.