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/test/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

以上是脚本

你可能感兴趣的:(操作系统,ssh)