Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Preventing "no matches found:"



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



Messages sorted by: Reverse Date, Date, Thread, Author