如何检查变量是否包含bash shell中的值

时间:2016-02-10 17:44:52

标签: bash shell

我很难检查变量的内容是否包含某个值,例如“Device_info”

主要代码

if [ "${NUMBERRESULTS}" -eq 10 ] 
then
    echo "Success"
else
    echo "Failed"
fi

上面的查询/脚本除了变量初始化产生了14个结果,当我运行它(devices.sh)这是准确的但在这种情况下我想验证$ NUMBERRESULTS变量或结果是否包含device_info值或不。见下文

这是我正在编写的代码

if [[ $NUMBERRESULTS =~ .*device_info.* ]] - i tried using the =~ operator
then
    echo "Success a device is present";
else
    echo "Failed no device is present"
fi

请参阅$ NUMBERRESULTS变量结果/内容中需要验证的值/字段。

"device_info": {      i need to check if this field/value is present or not.
    "connected_count": 36,
    "current_config_id": 1618,
    "default_config_id": 1618,
    "first_connected": 1454576905,
    "last_connected": 1454931872,
    "registered": 1454576905,
    "ip_address": "90.152.29.158",
    "model_number": "GT-I9505",
    "serial_number": "restful_api_device",
    "mac_address": "00:00:00:00:00:00",
    "smartcard": "unknown",
    "hardware_version": "0",
    "software_version": "83886336",
    "manufacturer": "SAMSUNG"

非常感谢

0 个答案:

没有答案