I am trying to find out whether disk is SSD or HDD using bash script.
logical_name="/dev/sda" type="" disk=$(basename $logical_name) x=`cat $filename | grep "${disk}" | awk '{print $2}'` if [ ! -z "$x" ] then if [ "$x" = "0" ] then type="SSD" fi if [ "$x" = "1" ] then type="HDD" fi fi echo $type Value of x is correct, 0 or 1. But after comparison, it's not assigning any value to variable type. It prints as empty. Can anyone point out what am I doing wrong here?
More information:
$filename is a file that contains output of sudo lsblk -d -o name,rota
NAME ROTA sda 1 sdd 1 sdc 0
sedto simplify this:lsblk -d -o name,rota | sed -e 's/0$/SSD/g' -e 's/1$/HDD/g'typeis empty at the end, that means the conditional has failed. Tryechoing the value ofxjust before firstifcondition (which seems redundant)bash -x yourfileand edit your post to include the debug log if the problem does not become immediately obvious