[Gllug] Changing case on filenames

James Tullett jamest at iotia2.demon.co.uk
Sun Mar 10 13:15:29 UTC 2002


On Saturday 09 Mar 2002 18:11 pm, you wrote:
> On Tue, 5 Mar 2002, Alain Williams said:
> > 	do	newfile=$( echo "$file" | tr '[A-Z]' '[a-z]' )
> > 		[[ $newfile = $file ]] && continue
>
> Note that these cases are very different. In [[ ]], the spaces around
> the [[ and ]] elements are necessary; but in $( ) they are not, viz
>
> newfile=$(echo "$file" | tr '[A-Z]' '[a-z]')
>
> is perfectly valid.
As are the Posix? character classes [:upper:], [:lower:] and friends.
man tr has the full details. for example
--------------8<----------------8<-----------------------8<-----------
#!/bin/bash
# lowercase.sh
for file in $@;
do
    ofile=$(echo $file |  tr '[:upper:]' '[:lower:]')
    if [ ! -f $ofile ]
    then
        mv -v $file $ofile
    fi
done
--------------8<----------------8<-----------------------8<-----------
James Tullett

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list