Bash Makefile删除文件
对于一个学校项目,我尝试使用makefile。首先,我用Bash Makefile删除文件,bash,makefile,pattern-matching,Bash,Makefile,Pattern Matching,对于一个学校项目,我尝试使用makefile。首先,我用 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 现在我要清除项目: clear: @if test -d *.[osia]; then rm *.[osia] else : ; fi @i
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
现在我要清除项目:
clear:
@if test -d *.[osia]; then rm *.[osia] else : ; fi
@if test -d a.out then rm a.out; else: ; fi
运行makeinstall可以正常工作。运行清除会产生错误代码:
/bin/sh: 1: test: main.i: unexpected operator
并且不会删除请求的文件。我想删除所有*.o*.s*.I和*.a
文件,方法是使用上述模式运行清除目标,避免出现错误无法删除…:没有这样的文件或目录
test
需要一个参数;当你把球传给它时,它会得到一堆球。在这种情况下,类似于find
的功能将起作用:
find . -maxdepth 1 -name '*.[osia]' -delete
或者,为什么要检查文件是否存在
rm -f *.[osia]
另外两个注意事项:如果if语句中没有else
子句,请不要包含它。读取测试
命令;如果要查找文件,您肯定不想使用-d
。而且,您可以使用变量$PWD
代替运行子shell来获取它。test
需要一个参数;当你把球传给它时,它会得到一堆球。在这种情况下,类似于find
的功能将起作用:
find . -maxdepth 1 -name '*.[osia]' -delete
或者,为什么要检查文件是否存在
rm -f *.[osia]
另外两个注意事项:如果if语句中没有else
子句,请不要包含它。读取测试
命令;如果要查找文件,您肯定不想使用-d
。而且,您可以使用变量$PWD
代替运行子shell来获取它