I am writing a script to check for a few things before installing a package. I need to check how much free space the filesystem containing the $PWD has. I wrote and tested the script on RHEL 7.0. I used df -m $PWD|awk {'print $4'}
to get the available free space. This works fine for RHEL 7.0. But in RHEL 6.4 and 7.1, this does not return the free space in MB, but the free % available space on the filesystem. Visually they look the same. I see that the version of the df
command is different from df --version
. This script is to be used across a large variety of RHEL systems. What can be a workaorund to this?
Use -P
with df
command
-P, --portability
use the POSIX output format
df -m -P $PWD| awk {'print $4'}