Linux Shell 学习笔记三

在Shell中调用Golang代码

powershell 复制代码
go run <script_name>.go

Jq

jq在线验证:https://jqplay.org/jq

jq-to_entries-map-from_entries

powershell 复制代码
[jiankunking@hddxps8156 jiankunking]# cat jq-entries.sh 
#!/bin/bash
data='{"a": "xxxx","b": "yyyy"}'
a=20
echo `echo $data| 
  jq 'to_entries'`

data=`echo $data| 
  jq 'to_entries | 
    map(if .key == "a" 
        then . + {"value":'$a'} 
        else . 
        end
        ) | 
    from_entries'`

echo $data    
if [ `echo $data | jq '.a'` -eq 20 ];then \
    echo 666
fi

data=`echo $data | sed 's/ //g'`
echo $data
[jiankunking@hddxps8156 jiankunking]# ./jq-entries.sh
[ { "key": "a", "value": "xxxx" }, { "key": "b", "value": "yyyy" } ]
{ "a": 20, "b": "yyyy" }
666
{"a":20,"b":"yyyy"}

jq-to_entries-select

powershell 复制代码
[jiankunking@hddxps8156 jiankunking]# kubectl get deployment test-admin -n i-test -ojson
{
    "apiVersion": "apps/v1",
    "kind": "Deployment",
    "metadata": {
        "labels": {
            "app": "test-admin",
            "app.kubernetes.io/name": "test-admin",
            "app.kubernetes.io/version": "v0"
        },
        "name": "test-admin",
        "namespace": "i-test",
        "resourceVersion": "2257518831",
        "uid": "4519e6a3-a881-4b16-9cff-83d2d7425bf6"
    },
    "spec": {},
    "status": {}
}
[jiankunking@hddxps8156 jiankunking]# kubectl get deployment test-admin -n i-test -ojson | jq '.metadata.labels'
{
  "app": "test-admin",
  "app.kubernetes.io/name": "test-admin",
  "app.kubernetes.io/version": "v0"
}
[jiankunking@hddxps8156 jiankunking]# kubectl get deployment test-admin -n i-test -ojson | jq '.metadata.labels'| jq -r 'to_entries[]| select(.key=="app.kubernetes.io/name")| .value'
test-admin
[jiankunking@hddxps8156 jiankunking]# 

作者:jiankunking 出处:http://blog.csdn.net/jiankunking

相关推荐
物联网老王2 小时前
Ubuntu Linux Cursor 安装与使用一
linux·运维·ubuntu
IMPYLH3 小时前
Python 的内置函数 reversed
笔记·python
一位摩羯座DBA4 小时前
Redhat&Centos挂载镜像
linux·运维·centos
学习3人组4 小时前
CentOS配置网络
linux·网络·centos
weixin_307779135 小时前
Hive集群之间迁移的Linux Shell脚本
大数据·linux·hive·bash·迁移学习
漫步企鹅5 小时前
【蓝牙】Linux Qt4查看已经配对的蓝牙信息
linux·qt·蓝牙·配对
码荼5 小时前
学习开发之hashmap
java·python·学习·哈希算法·个人开发·小白学开发·不花钱不花时间crud
cui_win5 小时前
【网络】Linux 内核优化实战 - net.core.flow_limit_table_len
linux·运维·网络
梦在深巷、5 小时前
MySQL/MariaDB数据库主从复制之基于二进制日志的方式
linux·数据库·mysql·mariadb
冰橙子id6 小时前
linux系统安全
linux·安全·系统安全