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

Re: how to rename multiple files



Hi,

"Gerald V. Livingston II" <debuser@sysmatrix.net> writes:

> Colin Watson said:
>
>> On Tue, Dec 10, 2002 at 11:20:31AM -0800, Osamu Aoki wrote:
>>> if [ -e *.JPG ]; then for i in *.JPG; do mv "$i" "${i%.JPG}.jpg";
>>> done fi
>>
>> That -e test looks dreadful ... surely it'll usually expand to lots of
>> arguments which will confuse [, or perhaps to an empty string
>> (nullglob)
>> which will also confuse test?
>>
>> --
>> Colin Watson
>> [cjwatson@flatline.org.uk]
>
> And I've bumped into this. How *DOES* one test for the existence of
> ANY file with a given extension without getting a "too many arguments"
> error when there are multiple files?
>
> I want "TRUE" if there is one or more zzz.jpg files in a directory,
> "FALSE" if there are zero of them.

Try

  list=`echo *.jpg`
  case $list in
  '*.jpg') echo "nothing to be done";;
  *) for i in $list; do mv $i `basename $i .jpg`.jpeg; done
  esac     

- Hari
-- 
Raja R Harinath ------------------------------ harinath@cs.umn.edu



Reply to: