[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: Christopher Roy Bratusek
Subject: Re: asking for a better way to implement this
Date: Sun, 26 Sep 2010 21:31:42 +0200

> 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.

> 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

reply via email to

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