_diskspace - UDM Built-in Variable


The _diskspace built-in variable contains the amount of available space (in bytes) on the volume or file system queried by the diskspace command.

This value is valid only after UDM executes a diskspace command. It retains its value until it is re-initialized with the set command or until UDM executes another diskspace command.

The _diskspace variable provides the following attributes, which allow convenient access to automatically converted quantities:

  • kb - the amount of available space in kilobytes, where 1 kb = 1,024 bytes
  • mb - the amount of available space in megabytes, where 1 mb = 1,048,576 bytes
  • gb - the amount of available space in gigabytes, where 1 gb = 1,073,741,824 bytes

To access any of the above attributes, add it to the variable name, separating the variable and attribute with a period ( . ). For example, use $(_diskspace.kb), $(_diskspace.mb), and $(_diskspace.gb) to access the available space in kilobytes, megabytes, and gigabytes, respectively.

To obtain the amount of available space in bytes, simply specify the _diskspace variable without any attributes.

Note

UDM stores converted quantities as floating point values. For example, if the diskspace command discovers that there are 2,621,440 bytes free on a given volume, when UDM converts the value to megabytes, $(_diskspace.mb) will return 2.5. However, UDM only performs integral calculations and comparisons.

In other words, given the following statement (where $(_diskspace.mb) is 2.5):

set fspc=<$(_diskspace.mb) + 20>

UDM sets $(fspc) to 22, not 22.5.


Likewise, UDM only recognizes the integral part of the $(_diskspace.xx) value when performing comparisons. For example, given a $(_diskspace.gb) value of 10.3:

if <$(_diskspace.gb) LT 10.5>
   echo "This statement is not displayed"
else
   echo "But this statement is"
end


UDM displays "But this statement is" even though 10.3 is less than 10.5. The reason for this is that UDM only recognizes the integral portion (that is, the "10") in each value. The quantities appear equal to UDM, so the LT test fails.

To make the way UDM evaluates the statement match its intent, change it to if <$(_diskspace.gb) LT 11>. The statement will now evaluate to true, because 10 is less than 11.