BASH: how would one execute rm on an array of file names? -


forgive noob-ness. have script want use remove non english .lproj files.

if [ -f /var/mobile/documents/local\ cookies/clean ];            echo "last run: $(cat /var/mobile/documents/local\ cookies/clean) "     else         echo "hasn't been run yet "     fi     echo (grave)date(grave) > /var/mobile/documents/local\ cookies/clean    sleep 1     echo "found files:"   lang=( $( find / -name "*.lproj" ! -name "en*" ! -name "en*" ! -name "base*" ) )   echo ${#lang[@]}   rm -r $lang >/dev/null 2>&1   echo "finished cleaning language files."   sleep 1   echo "found files:"   iphone=($( find /  -name "*~iphone" ) )   echo ${#iphone[@]}   rm -r $iphone >/dev/null 2>&1   echo "finished cleaning iphone files." 

the problem (being beginner) have no idea how might use rm -r $... parts remove files found on $lang , $iphone arrays.

another suggestion use xargs command combined find

lang=( $( find / -name "*.lproj" ! -name "en*" ! -name "en*" ! -name "base*" -type f | xargs rm -f) )  

btw should use variable lang check operation result

if [ -z "${lang}" ];then     echo "all files removed" fi 

you should made test make more efficient.

-rw-r--r-- 1 cg cg    0 jan 29 03:16 test1.lproj                                                                                                                                                           -rw-r--r-- 1 cg cg    0 jan 29 03:16 test3.lproj                                                                                                                                                           -rw-r--r-- 1 cg cg    0 jan 29 03:16 test2.lproj                                                                                                                                                           -rw-r--r-- 1 cg cg    0 jan 29 03:16 test4.lproj                                                                                                                                                           -rw-r--r-- 1 cg cg    0 jan 29 03:16 test5.lproj                                                                                                                                                           -rw-r--r-- 1 cg cg    0 jan 29 03:16 testen7.lproj                                                                                                                                                         -rw-r--r-- 1 cg cg    0 jan 29 03:16 test6.lproj                                                                                                                                                                                                                                                                                                                              -rw-r--r-- 1 cg cg    0 jan 29 03:16 testbas87.lproj                                                                                                           -rwxrwxrwx 1 cg cg  229 jan 29 03:16 test.sh   > result bash-4.3$ ./test.sh                                                                                                                                                                                        start                                                                                                                                                                                                      lang[]                                                                                                                                                                                                     files removed                                                                                                                                                                                          end                                                                                                                                                                                                        bash-4.3$   bash-4.3$ ls -ltr                                                                                                                                                                                          total 12                                                                                                                                                                                                    -rwxrwxrwx 1 cg cg  229 jan 29 03:16 test.sh                                                                                                                                                               

Comments