免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2934 | 回复: 4
打印 上一主题 下一主题

find -exec 中可否使用内建命令 [复制链接]

论坛徽章:
93
2015年辞旧岁徽章
日期:2019-10-10 10:51:15CU大牛徽章
日期:2014-02-21 14:21:56CU十二周年纪念徽章
日期:2020-10-15 16:55:55CU大牛徽章
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大牛徽章
日期:2019-10-10 10:55:38季节之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季节之章:冬
日期:2019-10-10 10:57:17CU大牛徽章
日期:2014-02-21 14:22:52CU大牛徽章
日期:2014-03-13 10:40:30CU大牛徽章
日期:2014-02-21 14:23:15
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-10-14 18:05 |只看该作者 |倒序浏览
想根据 a b 文件的新旧对比来决定是否继续后续操作。是不是内建命令不能放在 find 的 -exec 后呢?或者是我写的有问题吧?
注释的内容是可以正常工作的内容:

  1. [root@test test]# cat test.sh
  2. for (( i=0; i < 3; ++i ))
  3. do
  4.         echo "before"
  5.         find b -newer a -exec continue \;
  6.         # if [ -z "$(find a -newer b)" ]
  7.         # then
  8.         #       continue
  9.         # fi
  10.         echo "after"
  11. done
  12. [root@test test]# ./test.sh
  13. before
  14. find: continue: 没有那个文件或目录
  15. after
  16. before
  17. find: continue: 没有那个文件或目录
  18. after
  19. before
  20. find: continue: 没有那个文件或目录
  21. after
  22. [root@test test]#
复制代码

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
2 [报告]
发表于 2011-10-14 20:11 |只看该作者
The exec() family of functions replaces the current process image with a new process image.
这个exec的原义,我们就附会一下吧,
当find去exec continue时,去哪里找continue的image?

论坛徽章:
93
2015年辞旧岁徽章
日期:2019-10-10 10:51:15CU大牛徽章
日期:2014-02-21 14:21:56CU十二周年纪念徽章
日期:2020-10-15 16:55:55CU大牛徽章
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大牛徽章
日期:2019-10-10 10:55:38季节之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季节之章:冬
日期:2019-10-10 10:57:17CU大牛徽章
日期:2014-02-21 14:22:52CU大牛徽章
日期:2014-03-13 10:40:30CU大牛徽章
日期:2014-02-21 14:23:15
3 [报告]
发表于 2011-10-15 13:02 |只看该作者
回复 2# waker

谢谢 waker,你的那句话是哪里的说明,不会是 find 的源码说明吧,那太高深我是接触不到的,我在 find 的 man 中没有看到。
虽然说英文单词都认识,还是不大理解这句话的意思
The exec() family of functions replaces the current process image with a new process image.

理解成中文:exec()这一族的函数会用新的进程映像替换当前进程映像。是说用 -exec 后的命令替换了 find 命令进行执行吧?

这个exec的原义,我们就附会一下吧,
当find去exec continue时,去哪里找continue的image?

从执行的提示“没有那个文件或目录”来看,应该是指没有“continue”这个“文件”用于 -exec 的执行,也就是说 -exec 需要找到一个实实在在的命令文件来进行执行,这个“实实在在”的文件就是你说所的那个“image”吧?
综合来理解也就是说 -exec 是需要一个有“物理实体”的命令来做参数,所以内建命令就用不上了。

man find 里没有对 command 有什么限制的说明:
  1.       -exec command ;
  2.               Execute  command;  true  if 0 status is returned.  All following arguments to find are taken to be
  3.               arguments to the command until an argument consisting of ‘;’ is encountered.  The string  ‘{}’  is
  4.               replaced  by  the  current  file name being processed everywhere it occurs in the arguments to the
  5.               command, not just in arguments where it is alone, as in some versions of find.  Both of these con-
  6.               structions  might  need to be escaped (with a ‘\’) or quoted to protect them from expansion by the
  7.               shell.  See the EXAMPLES section for examples of the use of the  ‘-exec’  option.   The  specified
  8.               command  is  run  once  for each matched file.  The command is executed in the starting directory.
  9.               There are unavoidable security problems surrounding use of the -exec option; you  should  use  the
  10.               -execdir option instead.
复制代码

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
4 [报告]
发表于 2011-10-17 08:58 |只看该作者
回复 3# seesea2517

那就换种说法,我们这里讨论的"内建命令"是指shell内实现的一些功能,find怎么知道shell有哪些内建命令?如果你自己写了个程序里面有个子命令xxoo那find -exec xxoo行不行?

论坛徽章:
93
2015年辞旧岁徽章
日期:2019-10-10 10:51:15CU大牛徽章
日期:2014-02-21 14:21:56CU十二周年纪念徽章
日期:2020-10-15 16:55:55CU大牛徽章
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大牛徽章
日期:2019-10-10 10:55:38季节之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季节之章:冬
日期:2019-10-10 10:57:17CU大牛徽章
日期:2014-02-21 14:22:52CU大牛徽章
日期:2014-03-13 10:40:30CU大牛徽章
日期:2014-02-21 14:23:15
5 [报告]
发表于 2011-10-17 09:42 |只看该作者
回复 5# waker


    嗯,这个很好理解了,做为文盲的我还是喜欢听通俗一点的解释。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP