[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: asking for a better way to implement this

From: Dennis Williamson
Subject: Re: asking for a better way to implement this
Date: Sun, 26 Sep 2010 16:55:26 -0500

On Sun, Sep 26, 2010 at 2:31 PM, Christopher Roy Bratusek
<address@hidden> wrote:
>> Style is a matter of taste, but I think this is equivalent (not tested):
>>     xrm () {
>>         for path in "$@"; do
>>             test ${path:0:1} == - && local RMO+="$path " && continue
>>             for try in "$path" "${path%/*}"; do
>>                 test -e "$try"/.dirinfo || continue
>>                 grep -q NoDelete "$try"/.dirinfo || continue
>>                 echo "can not delete $try, it's protected"
>>                 continue 2
>>             done
>>             $(which rm) $RM_OPTS $RMO "$path"
>>         done
>>         }
> Looks better. And I found out about continue :)
>> A few points:
>> Since you don't quote $@ there's probably no reason to quote $path.
>> Your RMO will have options concatenated with no space between them.
>> Your sed 's///g' might misbehave, e.g., xrm /tmp/home/tmp.  The bash % 
>> expansion
>> only operates on the last pattern.
>> The -e option to sed seems to serve no purpose.
> Thanks.
>> I'm guessing your $(which rm) is intended to avoid calling rm(), but maybe 
>> \rm
>> would do the same thing?  No, that still calls the function... I'm not sure
>> how to do that.
> I'm doing alias rm="xrm" and it would call itself then.
>> This is the bug-bash list, maybe not the best place for this kind of thing...
> I've thought there's no other bash ML?
>> Ken
> Regards,
> Chris

It's a bad idea to alias rm. It would be better to use your xrm
directly. If you alias rm and get in the habit of it protecting you,
one of these days the alias won't be there and OOPS, gone!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]