HDD partition space check using the path input from user

I wrote a function which asks user the path and validates it; followed up by subsequent display of the HDD usage/available space for that particular partition of the drive which user entered path of. I am not sure why I am getting error

Code-

funcHDD () {
        read -p "Enter Path: " Path
        if [ -d $Path ]; then
                echo "Choose option from menu - HDD details:"
                echo "1. Used"
                echo "2. Available"
                read -p "Select: " HddUseAva
                tdisk=$(df -h "${Path}" | awk '{print $2}' | tail -1)
                udisk=$(df -h "${path}" | awk '{print $3}' | tail -1)
                adisk=$(df -h "${path}" | awk '{print $4}' | tail -1)
                fsys=$(df -h "${path}" | awk '{print $1}' | tail -1)
                if [ $HddUseAva = 1 ]; then
                        echo "Current used space in $fsys: $udisk  (Total: $tdisk)"
                elif [ $HddUseAva = 2 ]; then
                        echo "Current available space in $fsys: $adisk  (Total: $tdisk)"
                elif echo $HddUseAva | grep -iq 'Done'; then
                        exit
                elif echo $HddUseAva | grep -iq 'Exit'; then
                        exit
                else
                        funcHDD
                fi
        else
                echo "Invalid Path"
                funcHDD
        fi
        }

Error-

Enter Path: /home 
Choose option from menu - HDD details:
1. Used
2. Available
Select: 1
df: ‘’: No such file or directory
df: ‘’: No such file or directory
df: ‘’: No such file or directory
Current used space in :   (Total: 20G)

Answers


You use two different variables : $path and $Path, but $path is undefined.

Replace :

udisk=$(df -h "${path}" | awk '{print $3}' | tail -1)
adisk=$(df -h "${path}" | awk '{print $4}' | tail -1)
fsys=$(df -h "${path}" | awk '{print $1}' | tail -1)

with :

udisk=$(df -h "${Path}" | awk '{print $3}' | tail -1)
adisk=$(df -h "${Path}" | awk '{print $4}' | tail -1)
fsys=$(df -h "${Path}" | awk '{print $1}' | tail -1)

Need Your Help

Remove class when bottom of div reaches viewport bottom

javascript jquery html css css3

Im trying to create a parallax type effect where the image follows the user until the end of the content. Currently a class is added when the div reaches the top of the viewport however I am not ab...

SQL: large case conditions GROUP BY clause slow

sql oracle

I need to extract a report base on LC call number base on the number range. The call number format will be as below pattern and I need to extract the 2nd field before the punctuation for grouping: