- 论坛徽章:
- 2
|
各位,兄弟最近实现了一个可以递归把一个目录包括子目录中的所有文件转换成unix格式文件的shell script,但是如果一个文件名中间有空格(比如叫"how to do.txt")就会停止工作,我不知道如何解决,希望大侠们帮忙解决一下子,谢谢!
代码如下:
#!/bin/bash
#This script convert all the files within $1 directory to DOS format.
#bug:can't convert files if the filename contains spaces.
# -leiyu.
recursive_dos2unix()
{
for x in $(ls)
do
if [ -f "$x" ]
then
chmod a+w ./"$x"
dos2unix ./"$x"
chmod a-w ./"$x"
elif [ -L "$x" ]
then
echo "this is a link"
else
cd "$x"
if [ "$?" != "0" ]
then
echo "cd failed, exit now."
exit 1
fi
pwd
recursive_dos2unix
cd ..
fi
done
}
echo "Start convert"
cd $1
recursive_dos2unix
echo "end of convert" |
[ 本帖最后由 ytsmtipe 于 2009-6-9 11:55 编辑 ] |
|