users=$(ls /home --hide=lost+found) # This sets all content but 'lost+found' into the list: users
for usr in $users;do # For each entry (named: usr) in list 'users', do ....
space=$(du -hsx /home/$usr) # higly recomend 'x' if you mount other filesystems inside user dirs, 'h' makes it more 'readable'
echo "$usr space is $space"
done
ls /home --hide=lost+found > /root/users.txt # Write all content but 'lost+found' into the file: /root/users.txt, using
while read mama; do # For each line (named: mama), do ....
space=`du -s /home/$mama`
echo "$mama space is $space"
done < /root/users.txt # while reading from file
After executing the command mama=`cat /root/users.txt` , the command:
while read $mama; do
space=`du -s /home/$mama`
echo "$mama space is $space"
done
will be expanded by the shell to:
while read andy bob celia denise; do
space=`du -s /home/andy
bob
celia
denise`
echo "andy
bob
celia
denise space is $space"
done
which will read lines of text from standard input and assign the first word found on each line to the variable andy , the second word found on each line to the variable bob , the third word found on each line to the variable celia , and the remaining words on each line to the variable denise . I assume that rather than producing no output, it is actually sitting there waiting for you to type in a line in response to the read command.