shell脚本定义变量
查看当前shell中定义的全部环境变量:
$>env
查看某个进程的环境变量:
cat /proc/$PID/environ,PID是相关进程的进程ID
生成易读的报表,将cat命令的输出通过管道传给tr,将其中\0替换成\n,因为该文件默认以\0分隔
cat /proc/12501/environ | tr '\0' '\n'
shell中使用变量示例:
shell脚本定义数组
使用数值列表定义一个数组:
array_var=(test1 test2 test3 test4)
打印出特定索引的数组元素内容:
echo ${array_var[0]}
打印出特定索引的数组元素内容(二):
index=5 echo ${array_var[$index]}