Bash 删除命令行返回的第一条白线
我正在使用kubernetes,我想从应用程序名中获取podname。这是我使用的命令Bash 删除命令行返回的第一条白线,bash,kubernetes,kubectl,Bash,Kubernetes,Kubectl,我正在使用kubernetes,我想从应用程序名中获取podname。这是我使用的命令 POD=$(kubectl get pods -l app=influxdb-local -o custom-columns=:metadata.name -n influx) 然后,我想将结果用于: kubectl exec -it -n influx $POD -- influx -username user -password "user" -execute "CREATE DATABASE db"
POD=$(kubectl get pods -l app=influxdb-local -o custom-columns=:metadata.name -n influx)
然后,我想将结果用于:
kubectl exec -it -n influx $POD -- influx -username user -password "user" -execute "CREATE DATABASE db"
但是第一行是空的,第二行包含pod名称,所以第二个命令不起作用
如何删除第一条白线?添加--no headers
跳过标题行
kubectl get pods -l app=influxdb-local -o custom-columns=:metadata.name -n influx --no-headers
自定义列
使用标志-o custom columns=:
可以自定义输出
标题name
kubectl get pods -o custom-columns=NAME:metadata.name
输出
NAME
myapp-5b77df6c48-dbvnh
myapp-64d5985fdb-mcgcn
httpd-9497b648f-9vtbl
空标题名称:您将标志用作-o自定义列=:metadata.name
-第一行是标题行,但标题为空
省略标题
省略标题行的正确解决方案是使用标志--no headers
kubectl get pods -o custom-columns=NAME:metadata.name --no-headers
示例输出
myapp-5b77df6c48-dbvnh
myapp-64d5985fdb-mcgcn
httpd-9497b648f-9vtbl