shell提取指定列并判断提取结果中是否包含指定字符串

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Rocky_zhm/article/details/50035437

判断第一列是否包含某一个关键字,如果与关键字相等,则输出当前行的最后一列内容。

fileType=$( blkid | awk '{if($1=="关键字") {print $NF}}')

然后,在判断filetype中是否包含指定的字符串,

    if echo $fileType | grep -q "ext4"
    then
        echo "[INFO] Internal block has been formatted to exfat!"
    else
        echo "[INFO] Internal block's format is not exfat!"
    fi


或者

    if [ "$fileType" = "TYPE=\"exfat\"" ];
    then
        echo "[INFO] Internal block has been formatted to exfat!"
    else
        echo "[INFO] Internal block's format is not exfat!"
    fi

猜你喜欢

转载自blog.csdn.net/Rocky_zhm/article/details/50035437