Andrew Libby on 1 Feb 2006 18:00:50 -0000


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

Re: [PLUG] Interactive rm


Michael C. Toren wrote:

>Art Alexion wrote:
>  
>
>>>How can I restore rm's default behavior so that "rm *" requires
>>>confirmation, but "rm specified_file" does not?
>>>      
>>>
>
>gyoza@comcast.net wrote:
>  
>
>>Create an alias.
>>    
>>
>
>morgan wrote:
>  
>
>>If you're using bash you would create an alias:
>>
>>alias rm="rm -i"
>>    
>>
>
>Creating an alias won't solve Art's problem, which is using the "-i" flag
>when rm is passed multiple files, but not using "-i" when only a single
>file is specified -- rather, an alias will use "-i" in every case.  One
>possible solution is to create a bash function which determines how many
>arguments it was passed:
>
>	rm()
>	{
>	    if [ $# -lt 2 ]
>	    then /bin/rm $*
>	    else /bin/rm -i $*
>	    fi
>	}
>
>This works for the majority of cases:
>
>	[mct@ellesmere ~]$ touch foo bar baz
>	[mct@ellesmere ~]$ rm foo
>	[mct@ellesmere ~]$ rm bar baz
>	/bin/rm: remove `bar'? y
>	/bin/rm: remove `baz'? y
>  
>

This is a very cool solution!  A question I have is what art intended for
the following cases:

rm file1 file2
rm file*
rm file.???

My bet is that the first case, he'd not want interactive rm, but in the
second and third
he would.   Am I correct in my supposition that wild cards are expanded
prior to
invocation of the shell function?  That would make this desire
impossible, wouldn't it?
Anyone have any idea how we might expand this solution to accommodate
non-wild card
multi parameter invocations or rm?

-- 
Andrew Libby                                  
alibby@philadelphiariders.com
http://philadelphiariders.com/
Motorcycle Enthusiasm, Fishtown Style

1999 SV650
1999 Laverda 750S
1996 BMWR1100RS
1981 Moto Guzzi CX100 (in Lemans I clothing)


___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug