shell 提取json文件關鍵字

[
  {
    "outputType": {
      "type": "APK"
    },
    "apkData": {
      "type": "MAIN",
      "splits": [],
      "versionCode": 2019101910,
      "versionName": "6.2.0_beta1",
      "enabled": true,
      "outputFile": "app-development-debug.apk",
      "fullName": "developmentDebug",
      "baseName": "development-debug"
    },
    "path": "app-development-debug.apk",
    "properties": {}
  }
]

以上是JSON 文件的內容

 

#!/bin/sh

jsonpath='/root/liuqi/output1.json'
appcode=''
if [ ! -f $jsonpath ]; 
  then echo "file not exist"
  exit 0
fi
while read line
do  
   #contain keywords
  [[ $line =~ "versionCode"  ]] && {
  
    appcode=${line:15:10}          
    echo $appcode
  } 
done < $jsonpath

if [ ! -n :"$appcode" ]; then
  # empty 
  exit 0
fi


echo $appcode

以上是腳本

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章