I am taking input as memory ex. 10M or 50G  or 50 Kand I want to check this much size available in file system.for that I'm using df -h commanddf -Ph . | awk 'NR==2 {print $4}' I am getting 140M and my input may vary like 10k , 10M and 10GEX:my input is 20G and available memory in filesystem is 140MSo now how can I compare these two sizes (50G >140M ?) and echo output result.
how to compare filesystem sizes with -h human-readable suffixes in unix
linux;filesystems;memory;size
convert your available and input values to Kb and compare it..#!/bin/bashecho -n Enter the value ( value should end with G/M/K): read DISK_VALUEAVAILABLE_SPACE=$(df -h . | awk 'NR==2{print $4}')AVAILABLE_SPACE_IN_KB=$(echo ${AVAILABLE_SPACE} | awk '/M$/{print ($0+0)*1024}/G$/{print ($0+0)*1024*1024}/K$/{print $0+0}')COMPARE_VALUE_IN_KB=$(echo ${DISK_VALUE} | awk '/M$/{print ($0+0)*1024}/G$/{print ($0+0)*1024*1024}/K$/{print $0+0}')echo AVAILABLE_SPACE_IN_KB : ${AVAILABLE_SPACE_IN_KB}echo COMPARE_VALUE_IN_KB : ${COMPARE_VALUE_IN_KB}if [ ${AVAILABLE_SPACE_IN_KB} -lt ${COMPARE_VALUE_IN_KB} ]then        echo Available space (${AVAILABLE_SPACE}) is lesser than Given Value (${DISK_VALUE})else        echo Available space (${AVAILABLE_SPACE}) is greater than Given Value (${DISK_VALUE})fi$ bash a.shEnter the value : 1000KAVAILABLE_SPACE_IN_KB : 100COMPARE_VALUE_IN_KB : 1000Available space (100K) is lesser than Given Value (1000K)$ bash a.shEnter the value : 101MAVAILABLE_SPACE_IN_KB : 102400COMPARE_VALUE_IN_KB : 103424Available space (100M) is lesser than Given Value (101M)