I wrote the following command to list all files in and below '~' by order of file size. It seems to work fine:
find ~ -printf "%k KB %p\n" | sort -nr
Now I want to put this is a shell script and loop through the results to do more processing.
I got this to work with a simple 'ls' command:
dir="/home/myusername"
cmd='ls'
for i in `$cmd`
do
echo $i
done
But this doesn't work:
dir="/home/myusername"
cmd='find $dir -printf "%k KB %p\n" | sort -nr'
for i in `$cmd`
do
echo $i
done
I've also tried using escape characters in front of the double-quotes, but that didn't work either ...
dir="/home/myusername"
cmd='find $dir -printf \"%k KB %p\n\" | sort -nr'
for i in `$cmd`
do
echo $i
done
Any ideas what I'm doing wrong?