课时56:数组实践_综合实践_数组关联

1.2.1 数组关联

学习目标

这一节,我们从 基础知识、简单实践、小结 三个方面来学习。

基础知识

简介

powershell 复制代码
	上一节,我们学习了shell环境下的数组定制的简写方式。数组的定制主要有如下两种:
定制索引数组 - 数组的索引是普通的数字
	declare -a array_name
	- 普通数组可以不事先声明,直接使用
	
定制关联数组 - 数组的索引是自定义的字母
	declare -A array_name
	- 关联数组必须先声明,再使用

简单实践

实践1-定制索引数组

powershell 复制代码
定制一个空内容的数组
[root@localhost ~]# declare -a course
[root@localhost ~]# declare -a | grep course
declare -a course='()'

定制一个包含元素的数组
[root@localhost ~]# course=(yuwen shuxue yingyu)
[root@localhost ~]# declare -a | grep course
declare -a course='([0]="yuwen" [1]="shuxue" [2]="yingyu")'

实践2-定制关联数组

powershell 复制代码
定制关联数组
[root@localhost ~]# declare -A score
[root@localhost ~]# declare -a | grep score
[root@localhost ~]# declare -A | grep score
declare -A score='()'

关联数组和数字索引数组不能通用
[root@localhost ~]# declare -a score
-bash: declare: score: 无法将关联数组转化为索引数组
powershell 复制代码
关联数组的操作
[root@localhost ~]# declare -A | grep score
declare -A score='([yingyu]="32" [yuwen]="67" [shuxue]="65" )'
[root@localhost ~]# echo ${!score[@]}
yingyu yuwen shuxue
[root@localhost ~]# echo ${score[@]}
32 67 65

小结

复制代码
相关推荐
gx234841 分钟前
k8spod管理
linux·容器·kubernetes
susplus2 小时前
【linux应用软件编程】进程间的通信方式1【管道&IPC】
linux·进程通信·管道·ipc
AlfredZhao6 小时前
用 crontab 给 LLM 使用量装上“监控眼”
linux
疯狂打码的少年6 小时前
【数据库技术】关系模型基本概念(关系/属性/元组/键)
java·服务器·数据库·笔记
普马萨特8 小时前
实体与位置关系的数据从哪里来:获取、治理与仍待解决的问题
网络·数据库
sunshine8858 小时前
智能费控3.0:从合规审核到预算实时控制的进化之路
网络
刃神太酷啦8 小时前
Linux 系统 MySQL 完整安装配置教程:从卸载 MariaDB 到优化 my.cnf----《Hello MySQL!》(1)
android·linux·c语言·c++·mysql·leetcode·mariadb
赵文宇(温玉)9 小时前
OpenEuler24.03 SP4 系统安装(欧拉/麒麟V10)
linux·openeuler·欧拉
范什么特西9 小时前
回答网络-01
网络
2601_966799049 小时前
酷嗨米J300:一台相机同步推三平台
运维·服务器·负载均衡