The general statement is:
For f in 'ls ./'
However, if the file name contains spaces, for example, "a B", although ls can be correctly listed, for will use spaces as separators to assign A and B to F respectively, resulting in two file names.
Study found question mark? The file name can also contain spaces. Therefore, you can write as follows:
For f in 'ls./| TR """\? "'
First, replace the space in each line of LS with TR as the question mark. Such F can perform operations such as mV and CP. ECHO can also correct? It is displayed as a space. If String operations are involved, you can directly replace them in the variable.
F = 'tr "\? "<$ F'
Add a recursively changing the file name to lowercase.Program
#! /Bin/sh
function XX () {
Local oldpwd = "$ PWD"
Cd $1
Local F = ""
Local m = ""
for F in' ls. /| TR """\? "'
DO
echo $ F
# F = 'tr "\? "<$ F'
If [-d" $ F "]
then
xx" $ F "
fi
M = 'tr' [A-Z] ''[A-Z] '<" $ F "'
If [" $ F "! = "$ M"]
then
If [-e. /"$ M"]
then
echo in $ PWD: file $ F can \'t be transform since File $ M exists
else
mV. /"$ F ". /"$ M"
fi
done
Cd "$ oldpwd"
}< br> XX $1