Shell script - find: missing argument to `-exec'

女生的网名这么多〃 提交于 2021-01-29 15:00:18

问题


I'm trying to run this script:

alias logs="cd L:/"
find $logs -name '*system.log*' -mtime +14 -exec rm {} \;

But get this error: find: missing argument to `-exec'. I've tried looking at other posts on this but can't get it working. I'm using cygwin to run this script on Windows.


回答1:


If you have created any alias with name log, then to use it, you should be using $logs and not logs

Also, maybe the find you are using is of Windows and not of Cygwin. This is made clear if you type 'which find'




回答2:


First, some minor fixes:

#!/bin/sh
logs=/cygdrive/l
find "$logs" -name '*system.log*' -mtime +14 -exec rm -- {} +

...but those won't address your real problem (the one causing -exec to report an error), which is almost certainly the presence of DOS newlines in your script.

find -exec reports the error in question when it doesn't see an argument containing only the exact string ;. Outside quotes, \; should be that argument -- but it can be different if your file has hidden characters. And a DOS text file will appear to have hidden characters when opened by a program expecting a UNIX text file, because the two formats have different line separators.

To fix this, open the file in a native-UNIX editor such as vim, run :set fileformat=unix, and save it; or use dos2unix to convert it in-place.



来源:https://stackoverflow.com/questions/51859659/shell-script-find-missing-argument-to-exec

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!