Reputation: 1045
For a schoolproject I try around with makefiles. First I create the files with
install: main.c
gcc -asve-temps main.c
@if test ! -d bin/; then mkdir bin; else : fi
mv a.out $(shell pwd)/bin/
chmod 555 ./bin/a.out
Now I want to clear the project:
clear:
@if test -d *.[osia]; then rm *.[osia] else : ; fi
@if test -d a.out then rm a.out; else: ; fi
Running make install works fine. Running make clear
produces the error code:
/bin/sh: 1: test: main.i: unexpected operator
and does not remove the requested files. I want to delete all the *.o *.s *.i and *.a
files by running the make clear
target using the pattern given above avoiding the error cannot remove ... : no such file or directory
Upvotes: 0
Views: 3458
Reputation: 42712
test
expects a single argument; when you pass it a glob, it's getting a bunch of them. Something like find
will work in this case:
find . -maxdepth 1 -name '*.[osia]' -delete
Or, why check if the file exists at all?
rm -f *.[osia]
Couple of other notes: if you don't have an else
clause in your if statement, don't include it. Read up on the test
command; you certainly don't want to be using -d
if you're looking for files. And, you can use the variable $PWD
in place of running a subshell to get it.
Upvotes: 2