Art Alexion on 1 Feb 2006 20:20:16 -0000


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

Re: [PLUG] Interactive rm


bergman@merctech.com wrote:

>In the message dated: Wed, 01 Feb 2006 14:44:57 EST,
>The pithy ruminations from Art Alexion on 
><Re: [PLUG] Interactive rm> were:
>=> This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
>=> --------------enig82C6FEFB5B54D8F5D42F78F1
>=> Content-Type: text/plain; charset=ISO-8859-1
>=> Content-Transfer-Encoding: 7bit
>=> 
>=> bergman@merctech.com wrote:
>=> 
>=> >the original posted requested a slightly 
>=> >different behavior, as in:
>=> >	if there are multiple arguments to rm, then run rm interactively
>=> >	if there is a single argument to rm, then run rm non-interactively
>=> >
>=> >This is not as trivial as it appears. While it's easy to count the number of 
>=> >arguments and call "rm -i" if there's more than one argument, this doesn't deal 
>=> >correctly with arguments that are options, not the targets of the rm command. 
>=> >In addition, rm is sensitive to the order of arguments, and it's easy to get 
>=> >unexpected results when combining "-f" and "-i". I'm also skipping over the 
>=> >issues with targets that have embedded whitespace in their names...
>=> >
>=> >=> > How can I restore rm's default behavior so that "rm *" requires
>=> >=> > confirmation, but "rm specified_file" does not?
>=> >
>=> >Here's a bash shell function that will do what you want. This fragment of code 
>=> >can be put in your ~/.bashrc file. Note that the function, as named, will work 
>=> >when called as "myrm". You can change this to "rm" and therefore hide how "rm" 
>=> >really behaves.
>=> >  
>=> >
>=> Thank you Mark.  That does the trick.  A couple of test yield the
>=> following, though:
>=> 
>

>
>=>     * though it doesn't treat options as file arguments, it does not
>=>       pass the options to rm, so 'saferm -f *' still runs rm as 'rm -i *'
>
>Um, it _does_ pass the options to rm.
>
>Nope. If multiple targets are present, the function calls:
>	rm $all-options  -i  $targets
>this is because the "-f" and "-i" options are mutually exclusive, and whichever 
>appears last on the command line "wins". The original program specification 
>didn't say anything about using "-f", so the shell function puts "-i" last in 
>the list of options, thus overriding "-f" if it's present.
>
>Submit a change request to the development team, wait for managerial approval 
>and budgetary allocation. Depending on available resources and priority, and 
>the schedule of the test team, you should have the beta version by Q3 2006. 
>Once it's been approved by the User Acceptance Group, and the technical writer 
>updates the documentation, it can be released.  :)
>
>Or, you can edit the shell function, and change:
>	/bin/rm $options -i $targets
>to
>	/bin/rm -i $options $targets
>
>  
>
Yup.  I read that (last option wins) in either the rm man page or the
bash man page.  Thanks for the code change.

>=>     * You are right that it doesn't work with files with embedded spaces.
>
>:)
>
>=> 
>=> Thanks, again.  I really appreciate the help.
>
>Sure. Not a problem.
>  
>


-- 

_______________________________________
Art Alexion
Arthur S. Alexion LLC

PGP fingerprint: 52A4 B10C AA73 096F A661  92D2 3B65 8EAC ACC5 BA7A
The attachment -- signature.asc -- is my electronic signature; no need for alarm.
Info @ http://mysite.verizon.net/art.alexion/encryption/signature.asc.what.html

Key for signed PDFs available at
http://mysite.verizon.net/art.alexion/encryption/ArthurSAlexion.p7c
The validation string is TTJY-ZILJ-BJJG.
________________________________________

Attachment: signature.asc
Description: OpenPGP digital signature

___________________________________________________________________________
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