I'm trying to write a simple script:
stat=$(du /home/test/)
for i in "$stat"; do
folder=$("$i" | awk '{print $2}')
mail -s $folder [email protected]
done
I run the script in shell and the output looks like:
4 /home/test/.config/mc/mcedit
12 /home/test/.config/mc
16 /home/test/.config
I then insert echo in the script before the loop, and the output then looks like:
4 /home/test/.config/mc/mcedit 12 /home/test/.config/mc 16 /home/test/.config
This is because without double-quotes. With double-quotes output is the same as in shell. So then using double-quotes for variables in loop cycle variable $folder don't work as expected. Instead it contains all values from list.
How to resolve this?
duintoawkandforloop directly ?