Question: I am trying to write a bash script to list the size of each file/subdir of the current directory, as follows:

```
for f in $(ls -A)
do
    du -sh $f
done

```

I used `ls -A` because I need to include hidden files/dirs starting with a dot, like `.ssh`. However, the script above cannot handle spaces if the file names in `$f` contain spaces.
e.g. I have a file called:

```
books to borrow.doc

```

and the above script will return:

```
du: cannot access `books': No such file or directory
du: cannot access `to': No such file or directory
du: cannot access `borrow.doc': No such file or directory

```

There is a similar question [Shell script issue with filenames containing spaces](https://stackoverflow.com/questions/15511006/), but the list of names to process is from expanding `*` (instead of `ls -A`). The answer to that question was to add double quotes to `$f`. I tried the same, i.e., changing 

```
    du -sh $f

```

to 

```
    du -sh "$f"

```

but the result is the same. My question is how to write the script to handle spaces here?

Thanks.

Answer: 
Unless the directory is so big that the list of file names is too big:

```
du -sh * .*

```

Be aware that this will include `.` and `..`, though. If you want to eliminate `..` (probably a good idea), you can use:

```
for file in * .*
do
    [ "$file" = ".." ] && continue
    du -sh "$file"  # Double quotes important
done

```

You can consider assigning the names to an array and then working on the array:

```
files=( * .* )
for file in "${files[@]}"
do
    ...
done

```

You might use variations on that to run `du` on groups of names, but you could also consider using:

```
printf "%s\0" "${files[@]}" | xargs -0 du -sh

```
Time to summarize. Assuming you are using Linux, this should work in most (if not all) cases.

```
find -maxdepth 1 -mindepth 1 -print0 | xargs -r -0 du -sh

```