使用“查找"时出错unix 中的命令 [英] error using "find" command in unix

查看:24
本文介绍了使用“查找"时出错unix 中的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在尝试下面的代码,但它不起作用..请建议更正此代码..

I was just trying the below code and it is not working.. please suggest to correct this code..

echo abc.txt | while read name; do find . -name $name; done

输出成功:./rak/abc.txt

output success : ./rak/abc.txt

echo 'abc.txt pqr.txt' | while read name; do find . -name $name; done

输出错误:查找:0652-009 缺少连词

output error : find: 0652-009 There is a missing conjunction

echo "abc.txt pqr.txt" | while read name; do find . -name $name; done

输出错误:查找:0652-009 缺少连词

output error : find: 0652-009 There is a missing conjunction

同样的错误

echo "abc.txt" "pqr.txt" | while read name; do find . -name $name; done
echo 'abc.txt' 'pqr.txt' | while read name; do find . -name $name; done

请建议如何解决此问题...

Please suggest how to resolve this problem...

推荐答案

问题是多个条目作为一行发送到管道中,读取将两个字符串都拾取到 name 然后处理包含两个字符串的 $name.

The problem is that the multiple entries are sent into the pipe as one line, the read picks up both strings into name and then processes the $name containing the two strings.

你应该使用类似的东西:

You should use something like:

echo -e "abc.txt\npqr.txt" | while read name; do find . -name $name; done

即用换行符分隔项目.

您应该尝试使用 echo "'$name'" 而不是 find 来调试它,它会暗示发生了什么.

You should have tried debugging this by using echo "'$name'" instead of the find and it would have hinted what was happening.

此外,我会在查找中引用 $name 的使用,就好像文件名的名称中应该有一个空格一样,那么您将收到与您相同的错误消息原来经历过.

Additionally, I would use quoting around the use of $name in the find, as if the filename is expected to have a space in it's name then you will get the same error message as you have experienced originally.

这篇关于使用“查找"时出错unix 中的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆