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

Re: remove files sensibly



> Hi all:
> 
> How would I enter a command (or write a simple script) that would do:
> 
> FOR EACH FILE *.elc IF THERE IS CORRESPONDING *.el, DELETE IT
> 
> Are there any good online resources about writing similar scripts?

I found this web page, under the Unix shells section in Yahoo:

http://www.ocean.odu.edu/ug/shell_help.html

This is a tutorial on shell programmming.  Together with the bash info
page, it provides what you need to do this and far more.  (In the bash
info manual, look specifically at the section "Shell Parameter
Expansion".)

BTW, I will assume you mean to delete the *.el files.  If it is the
other way around you meant, the changes to the script below should be
obvious.

----- BEGIN HERE -----
#!/bin/bash

for objfile in *.elc
do
   srcfile=${objfile%.elc}.el
   if [ -f $srcfile ]
   then
       rm -f $srcfile
   fi
done


Reply to: