linux - How to read spaces in FOR loop -


this question has answer here:

i'm new here. trying write de-bloat script android. below code :-

#/system/bin/sh clear list=$(cat <<'eof' beauty\ plus blackmart cam\ scanner tencent eof )  f in $(echo "$list"); if [ -e /sdcard/$f* ];         rm -rf /sdcard/$f*     echo -e "deleted /sdcard/$f*." else     echo -e "/sdcard/$f* not found." fi done 

now here issue, reads both occurrences space different entries. have made sure use echo variables enclosed in quotes.

if try

echo "$list" 

then, gives desired output. have tried using the

echo "$list" | while read f echo $f done 

but, gives same output. please me this. output should :-

beauty\ circle cam\ scanner 

so write further code :-

for f in $(echo "list"); rm -rf /sdcard/$f echo -e "removed \/sdcard\/$f" done 

thank you.

p.s: don't want use

rm -rf /sdcard/$f* 

if need run script /bin/sh (which might shell not support arrays), need use while loop instead of for loop:

while ifs= read -r f;   rm -rf /sdcard/"$f"   printf 'removed /sdcard/%s\n' "$f" done <<eof beauty plus blackmart cam scanner tencent eof  

if can use #!/bin/bash, can use for loop iterate on array instead of regular parameter.

list=( "beauty plus" blackmart "cam scanner" tencent ) f in "${list[@]}";   rm -rf /sdcard/"$f"   printf 'removed /sdcard/%s\n' "$f" done 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -