linux - How to Save linux command output as list in variable
问题描述
Below command is running on linux system and I want to save output as list.
root@Linux:~ kubectl get ns | awk '{print $1}'
NAME
b2
b6
b7
cert-manager
I need to save above command output in to variable as list.
Example:-
NAMESPACE = ['NAME', 'b2', 'b6', 'b7', 'cert-manager']
NAMESPACE is variable
解决方案
If the output includes only simple words you can write like this:
$ arr=( $( echo a b c d ) )
$ for i in "${arr[@]}"; do echo "$i"; done
a
b
c
d
$ arr=$( echo a b c d )
$ for i in $arr; do echo "$i"; done
a
b
c
d
$
推荐阅读
- scala - scala 在运行时动态读取配置
- python - 在 csv 中搜索列中的字符串并仅显示特定列
- python - 寻找曼哈顿距离最近的元素效率不高
- javascript - 如何使每个角度分量具有不同的数组值
- html - 背景图像不会动态加载
- wireless - 无线传感器网络中的信任机制
- java - conflit version java :UnsupportedClassVersionError: .class 文件中的错误版本号
- java - Spark rdd处理java日期错误
- javascript - 使用 executeScript 和 SendMessage 的 chrome 扩展中的执行顺序
- php - 在 Woocommerce 中发送带有动态主题和收件人的自定义电子邮件