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

以上是脚本

发布了67 篇原创文章 · 获赞 6 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/sfmcatl/article/details/102639193