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

相关推荐
外收内放42 分钟前
数据分析(数据排序)
python·学习·数据分析
H.莓飛42 分钟前
【Linux】进程的创建与终止
linux·运维·服务器·c语言·visual studio
blueSatchel1 小时前
关于dev下节点的创建
linux·嵌入式
老秦包你会1 小时前
Linux第十课---------进程间通信
linux
AI小云1 小时前
零基础如何系统学习AI?2026年技术路径与培训选择深度分析
人工智能·学习
我命由我123451 小时前
准入类与水平类职业资格
笔记·学习·职场和发展·产品运营·求职招聘·职场发展·产品经理
He BianGu1 小时前
【笔记】在WPF中BitmapScalingMode的作用
笔记·wpf
宋明河1 小时前
windows与ubuntu双系统主机下ubuntu访问windows磁盘是只读
linux·windows·ubuntu
chenxy021 小时前
国产加速卡-应知应会
linux·运维·服务器
HackTwoHub1 小时前
免 Root 安卓渗透工具 Stryker|把 Kali 装进手机!随身无线渗透工作站,内置 Nmap/Nuclei/Metasploit 全套武器库
android·linux·运维·人工智能·web安全·macos·智能手机