问题
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