如何写这个命令?
发表于 : 2010-10-29 22:46
例如我查找一个名字为x的文件,然后用file命令判断文件x的文件类型
我用这样的管道命令好像不行,
find / -name x | file
如何写这段管道命令??
我用这样的管道命令好像不行,
find / -name x | file
如何写这段管道命令??
你的意思是这个?zhusongd 写了:这个命令参数也知道,能不能有一种方法,通过变量传递参数
可以这样。zhusongd 写了:这个命令参数也知道,能不能有一种方法,通过变量传递参数
你试试这个!daniel.supremacy 写了:上面两楼都不能处理有空格的文件吧![]()
高人指点迷津
代码: 全选
#!/bin/sh
find -name "xxx yyy"> tmpfile
IFS="\n"
for i in `cat tmpfile`
do
file $i
done
rm tmpfile
麻烦先test再发上来,我把处理结果放这里:bzhao 写了: 你试试这个!代码: 全选
#!/bin/sh find -name "xxx yyy"> tmpfile IFS="\n" for i in `cat tmpfile` do file $i done rm tmpfile
代码: 全选
$ ls -lh test*
-rw-r--r-- 1 daniel daniel 0 2010-10-30 10:46 test file
-rw-r--r-- 1 daniel daniel 0 2010-10-30 10:46 test saf
-rwxr-xr-x 1 daniel daniel 102 2010-10-30 10:46 test.sh
代码: 全选
$ cat test.sh
#!/bin/sh
find -name "test*" > tmpfile
IFS="\n"
for i in `cat tmpfile`
do
file $i
done
rm tmpfile
代码: 全选
$ ./test.sh
./test saf
./test file
./test.sh: ERROR: cannot open `./test saf
./test file
./test.sh' (No such file or directory)
代码: 全选
$ cat test.sh
#!/bin/sh
find -name "test*" > tmpfile
IFS="
"
for i in `cat tmpfile`
do
file $i
done
rm tmpfile
代码: 全选
$ ./test.sh
./test saf: empty
./test file: empty
./test.sh: POSIX shell script text executable
daniel.supremacy 写了:麻烦先test再发上来,我把处理结果放这里:bzhao 写了: 你试试这个!代码: 全选
#!/bin/sh find -name "xxx yyy"> tmpfile IFS="\n" for i in `cat tmpfile` do file $i done rm tmpfile
代码: 全选
$ ls -lh test* -rw-r--r-- 1 daniel daniel 0 2010-10-30 10:46 test file -rw-r--r-- 1 daniel daniel 0 2010-10-30 10:46 test saf -rwxr-xr-x 1 daniel daniel 102 2010-10-30 10:46 test.sh
代码: 全选
$ cat test.sh #!/bin/sh find -name "test*" > tmpfile IFS="\n" for i in `cat tmpfile` do file $i done rm tmpfile
============编辑的封个先==============代码: 全选
$ ./test.sh ./test saf ./test file ./test.sh: ERROR: cannot open `./test saf ./test file ./test.sh' (No such file or directory)
这个可以运行代码: 全选
$ cat test.sh #!/bin/sh find -name "test*" > tmpfile IFS=" " for i in `cat tmpfile` do file $i done rm tmpfile
代码: 全选
$ ./test.sh ./test saf: empty ./test file: empty ./test.sh: POSIX shell script text executable