标签:
方法一:设置IFS(the Internal Field Separator),不要用空格做为IFS,选择其他的符号。先来看看man page:
IFS: The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read built-in command. The default value is “<space><tab><new-line>”.
[xx@WW testtttttt]$ for i in *;do echo $i;done
1 .txt
2 .txt
方法二:就是在对文件名进行处理之前,先将空格替换为特殊的自定义符号,然后在处理结束的时候,再替换回来
safename="$(echo name | sed ‘s/ /_-_/g‘)"
original="$(echo $safename | sed s‘/_-_/ /g‘)"
方法三:利用find命令。
[xx@WWW testtttttt]$ find . -type f -print0
./2 .txt./1 .txt[op@TIM testtttttt]$
[xx@WWW testtttttt]$ find . -type f -print0 | while read -d $‘\0‘ file;do mv "$file" "$(echo $file |sed ‘s/ /_/g‘)";done
方法四:
标签:
原文地址:http://www.cnblogs.com/timdes/p/4860709.html