* Preventing "no matches found:" @ 2005-07-22 22:24 Tim McNerney 2005-07-22 23:01 ` Jos Backus 0 siblings, 1 reply; 5+ messages in thread From: Tim McNerney @ 2005-07-22 22:24 UTC (permalink / raw) To: zsh-users Is there some way to indicate that patterns may have no matches? I am doing a cron job that does cleanup of all files older than a certain time and have a line like: rm ~/log/**/*.log(m+7) and would like to avoid the message: no matches found: ~/log/**/*.log(m+7) by somehow indicating, either through a setopt or a parameter for (), that no matches is not an error. Thanks. --Tim ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Preventing "no matches found:" 2005-07-22 22:24 Preventing "no matches found:" Tim McNerney @ 2005-07-22 23:01 ` Jos Backus 2005-07-23 0:14 ` John Reese 0 siblings, 1 reply; 5+ messages in thread From: Jos Backus @ 2005-07-22 23:01 UTC (permalink / raw) To: zsh-users On Fri, Jul 22, 2005 at 03:24:31PM -0700, Tim McNerney wrote: > rm ~/log/**/*.log(m+7) > > and would like to avoid the message: > > no matches found: ~/log/**/*.log(m+7) You could try this: % setopt nullglob % echo ~/log/**/*.log(m+7) | xargs rm -- Jos Backus jos at catnook.com ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Preventing "no matches found:" 2005-07-22 23:01 ` Jos Backus @ 2005-07-23 0:14 ` John Reese 2005-07-23 2:10 ` Jos Backus 0 siblings, 1 reply; 5+ messages in thread From: John Reese @ 2005-07-23 0:14 UTC (permalink / raw) To: zsh-users 2005/7/22, Jos Backus <jos@catnook.com>: > On Fri, Jul 22, 2005 at 03:24:31PM -0700, Tim McNerney wrote: > > rm ~/log/**/*.log(m+7) > > > > and would like to avoid the message: > > > > no matches found: ~/log/**/*.log(m+7) > > You could try this: > > % setopt nullglob > % echo ~/log/**/*.log(m+7) | xargs rm > > -- > Jos Backus > jos at catnook.com > You can turn on noglob for a single pattern by adding a (N) flag. So you could just do: rm ~/log/**/*.log(m+7,N) But that doesn't really solve your problem, because if rm has no arguments, it'll complain. Now, my personal advice would be to not care, but if you do care, you could do this: deadlogs=(~/log/**/*.log(m+7,N)) ((#deadlogs)) && rm $deadlogs ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Preventing "no matches found:" 2005-07-23 0:14 ` John Reese @ 2005-07-23 2:10 ` Jos Backus 2005-07-23 6:47 ` Tim McNerney 0 siblings, 1 reply; 5+ messages in thread From: Jos Backus @ 2005-07-23 2:10 UTC (permalink / raw) To: zsh-users On Fri, Jul 22, 2005 at 05:14:49PM -0700, John Reese wrote: > You can turn on noglob for a single pattern by adding a (N) flag. So > you could just do: > > rm ~/log/**/*.log(m+7,N) I knew there was a flag like that but I couldn't find it offhand. > But that doesn't really solve your problem, because if rm has no > arguments, it'll complain. Now, my personal advice would be to not > care, but if you do care, you could do this: > deadlogs=(~/log/**/*.log(m+7,N)) > ((#deadlogs)) && rm $deadlogs I used xargs so rm would never be called without arguments, avoiding this problem. But your solution is a little more flexible, e.g. you could emit a message depending on whether any files will be/were removed: deadlogs=(~/log/**/*.log(m+7,N)) if (( $#deadlogs == 0 )) then echo "No longs removed." else rm $deadlogs echo "$#deadlogs logs removed." fi -- Jos Backus jos at catnook.com ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Preventing "no matches found:" 2005-07-23 2:10 ` Jos Backus @ 2005-07-23 6:47 ` Tim McNerney 0 siblings, 0 replies; 5+ messages in thread From: Tim McNerney @ 2005-07-23 6:47 UTC (permalink / raw) To: zsh-users Thanks to both. I was looking for the ,N, as I've come up with a few methods to "silence" it otherwise, but I felt there was likely a more elegant manner. --Tim On Jul 22, 2005, at 7:10 PM, Jos Backus wrote: > On Fri, Jul 22, 2005 at 05:14:49PM -0700, John Reese wrote: > >> You can turn on noglob for a single pattern by adding a (N) flag. So >> you could just do: >> >> rm ~/log/**/*.log(m+7,N) >> > > I knew there was a flag like that but I couldn't find it offhand. > > >> But that doesn't really solve your problem, because if rm has no >> arguments, it'll complain. Now, my personal advice would be to not >> care, but if you do care, you could do this: >> deadlogs=(~/log/**/*.log(m+7,N)) >> ((#deadlogs)) && rm $deadlogs >> > > I used xargs so rm would never be called without arguments, > avoiding this > problem. But your solution is a little more flexible, e.g. you > could emit a > message depending on whether any files will be/were removed: > > deadlogs=(~/log/**/*.log(m+7,N)) > if (( $#deadlogs == 0 )) > then > echo "No longs removed." > else > rm $deadlogs > echo "$#deadlogs logs removed." > fi > > -- > Jos Backus > jos at catnook.com > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-07-23 6:47 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-07-22 22:24 Preventing "no matches found:" Tim McNerney 2005-07-22 23:01 ` Jos Backus 2005-07-23 0:14 ` John Reese 2005-07-23 2:10 ` Jos Backus 2005-07-23 6:47 ` Tim McNerney
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).