|
#!/bin/bash
# 名称:delspace.sh
# 功能:将文件名中的空格替换成一个下划线。
# 用法1、批量替换:find * -type d -exec /path/delspace.sh {} \;
# 用法2、替换当前目录:/path/delspace.sh ./
if test -z "$1"; then
echo "String is null or empty"
else
echo "$1"
cd "$1"
ls | while read i; do
j=`echo $i|tr -s ' ' '_'`
if test "$i" != "$j"; then
mv "$i" "$j"
fi
done
fi
---------------------------------------------------------------------
参考资料:
KornLee
===============================
ls|while read i;do
mv "$i" $(echo $i|tr -d ' ') 2>/dev/null
done
=============================== |
|