I\'m trying to output the amount of free disk space on the filesystem /example.
If I run the command df -k /example I can get good informat
You can use stat(2) command to display free blocks and also to find out how large each block is, e.g.
stat -f --printf="%a %s\n" /
will display number of free blocks (%a) on a given file system (/) followed by a block size (%s). To get size in kB, you can use bc(1) command as in the following example:
stat -f --printf="%a * %s / 1024\n" / | bc
Finally, to put this into a variable is just a matter of using backtick substitution (or $() as in the first answer):
SOMEVAR=`stat -f --printf="%a * %s / 1024\n" / | bc`