Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm trying to loop through all file 2

Status
Not open for further replies.

pavNell

Technical User
Sep 27, 2002
178
US
I'm trying to loop through all filenames in the current directory and replace any filenames that contain uppercase letters to lowercase letters. I'm using tr in a while loop but tr does not do the job in a script. Here's my while loop...

ls -1 | while read filename
do
newname=`echo $filename | tr A-Z a-z`
mv $filename $newname
done

if I echo $newname in the loop, the translation works fine. But mv doesn't like it. Any fixes or suggestions?
 
for i in *
do
newname=`echo "${filename}" | tr A-Z a-z`
mv "${filename}" "${newname}"
done vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Try this...
[tt]
#!/bin/ksh

typeset -l LOWERCASENAME

for FILENAME in `ls -1`
do
LOWERCASENAME=${FILENAME}
if [[ -f ${LOWERCASENAME} ]]
then
print &quot;ERROR: ${LOWERCASENAME} already exists!&quot;
else
mv ${FILENAME} ${LOWERCASENAME}
fi
done
[/tt]
Hope this helps.

 
Thanks to both of you. They both worked great. Stars for vlad and Sambones!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top