Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Why does this CASE statement works with AWK but not with CUT?

I'm trying to execute a case statement, after running a df command and extracting a value returned from the output, It works perfectly when AWK command is used, but not with the CUT command. Can someone please explain why is this happening. In both the cases; if I echo the value; they remain the same. Trying this on MAC. Not an actual Unix/Linux machine.

Working Code:

#!/bin/bash

valueb=$( df -h | awk '{ print $5 }' | sort -n | tail -n 1 | tr '%' ' ' )


echo $valueb


case $valueb in
[1-100]*)


echo "The Disk space is $valueb"


;;


esac

NOT Working Code:

#!/bin/bash

valueb=$( df -h | cut -c 36-44 | sort -n | tail -n 1 | tr '%' ' ' )

echo $valueb


case $valueb in
[1-100]*)


echo "The Disk space is $valueb"


;;


esac

Expected to print the "This Disk space is 100". Which is working fine for AWK. But not when the cut command is used.

Comments