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

相关推荐
戴为沐20 小时前
Linux内存扩容指南
linux
zylyehuo1 天前
Linux 彻底且安全地删除文件
linux
用户805533698032 天前
主线 U-Boot 上 RK3506:和闭源 rkbin 拔河的三个隐性契约
linux·嵌入式
用户034095297912 天前
linux fcitx 5 雾凇拼音 设置在中文输入法下仍然输入英文标点
linux
Web3探索者4 天前
可视化服务器管理和传统命令行区别是什么?新手教程:Linux 运维到底该用图形界面还是 SSH 命令行?
linux·ssh
zylyehuo4 天前
Linux系统中网线与USB网络共享冲突
linux
Sokach10155 天前
Linux Shell 脚本从零到能用:一个新手的一天学习总结
linux
AlfredZhao5 天前
Docker 容器时区不对,`timedatectl` 不存在怎么办?
linux·timezone
LinXunFeng6 天前
Obsidian - 使用 Share Note 分享笔记并自部署
前端·笔记·github
zzzzzz3107 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql