Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Makefile删除文件_Bash_Makefile_Pattern Matching - Fatal编程技术网

Bash 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

对于一个学校项目,我尝试使用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
@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来获取它