Re: capital ->lower case?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Birre wrote:
> Lew Pitcher wrote:
>
> roN wrote:
>
>>>> Hi,
>>>>
>>>> I have a dir full of files with capital letter like PICTURE.GIF and I
>>>> need
>>>> all in lower case, is there any function to do this?
>>>> Thank you!
>
>
>
>> Assuming that there are no files with lower-case names that match the
>> upper
>> cased filenames (i.e. no "picture.gif" files already in the
>> directory), and
>> that none of the upper-cased filenames will collide when changed to
>> lower case
>> (i.e. none of "Picture.GIF" vs "PICTURE.GIF"), then this should do the
>> trick:
>>
>> for $FILE in * ;
>> do
>> $file=`echo $file | tr '[A-Z]' '[a-z]'`
>> mv "$FILE" "$file"
>> done
>>
>> There are probably simpler ways to do this, though.

> It should be tr '[:upper:]' '[:lower:]' , since not all users follow
> the rule to limit file names to US ascii.

I'll agree to that one. My solution was "quick and dirty", and I missed
that nuance.

> And it must be echo "$file" ,

Here, I'll disagree with you. The quotes aren't necessary in the echo
statement. Since $file will contain the filename, spaces and all,
echo $file
will output the filename (spaces and all) to stdout.
echo "$file"
would also output the filename (spaces and all) to stdout. There would
be no difference in the output at all

However, quotes would be needed in the
mv "$FILE" "$file"
command, because if either of the variables contained filenames with
spaces, the quotes are needed to bind the components together so that
commandline processing doesn't take them as separate arguments to the mv
command.

> since the rule to never add space in directory and file names"
> is ignored even by developers. (to make windows users feel @ home)

Sorry, but no. Unix filenames have never had the requirement (even
informally) of excluding spaces or other whitespace characters. As far
as the system is concerned, the only characters /not/ allowed in a file
or directory name are the NULL (0x00) character, and the '/' character.

It has been a /convenience/ for shell scripts to avoid filenames with
whitespace, otherwise you have to use quotes. A /convenience/ only, not
a rule.

> /birre Registered Linux User #18410 (http://counter.li.org/)
> SuSE - Because I know nothing :-)


- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFD1jOjagVFX4UWr64RAvniAJ45+0epvcBoPP6/TogBjP1Bzc3q1gCfQ3m4
cCzXpVpskfj/AXupawUHTcw=
=ZaAC
-----END PGP SIGNATURE-----
.



Relevant Pages

  • Re: loop and list with bash
    ... quotes in shells have a totally different puropose than in other ... Another side effect of leaving a command substitution unquoted ... >> filenames with special characters in them. ...
    (comp.unix.shell)
  • Re: escaping within multi-substitution
    ... Command line processing of eval $AWK and eval "$AWK" ... which means double quotes are not ... echo 'a b c d e f' | eval "$AWK" ... you used characters that shells ...
    (comp.unix.shell)
  • Re: How to output a list to a line?
    ... on one line with quotes around each file name and a space between them. ... SetLocal EnableDelayedExpansion ... echo %Line% ... and ensures that no additional blank characters are present in the output. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: DOS Prompt
    ... I have tried using 'rename' but cannot get it to work. ... echo Remove Leading Characters from filenames. ... ENSURE THAT ALL FILENAMES EXCEED x CHARACTERS! ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: DOS Prompt
    ... echo Remove Leading Characters from filenames. ... ENSURE THAT ALL FILENAMES EXCEED x CHARACTERS! ... REM delete echo in next line to rename files ...
    (microsoft.public.win2000.cmdprompt.admin)