2022年2月22日星期二

shell for loop in ls with filenames have spaces. IFS=$(echo -en "\n\b")

 ref: https://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html


#save current ifs singno
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for src_file in `find $rootpath -type f -name "* *" | grep -iE "\.($namefilter)" `; do
    echo "src_file=" $src_file 
done
#
IFS=$SAVEIFS


files=(`ls -1 zip/`)
for file_name in "${files[@]}"; do
    echo ${file_name}
   # cp -rf zip/${file_name}/src/main src/
done

没有评论: