> For the complete documentation index, see [llms.txt](https://zpliu.gitbook.io/booknote/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zpliu.gitbook.io/booknote/linux/zi-dian-yu-shu-zu.md).

# bash中的字典与数组

## 数组使用

## 字典的使用

```bash
declare -A sample
# 初始化字典
sample=(
[SRR8090044]=TM1_10DPA_Fiber_1
[SRR8090041]=TM1_10DPA_Fiber_2
[SRR8090042]=TM1_10DPA_Fiber_3
[SRR8090046]=TM1_15DPA_Fiber_1
[SRR8090049]=TM1_15DPA_Fiber_2
[SRR8090050]=TM1_15DPA_Fiber_3
[SRR8090004]=TM1_20DPA_Fiber_1
[SRR8090007]=TM1_20DPA_Fiber_2
[SRR8090006]=TM1_20DPA_Fiber_3
[SRR8090010]=TM1_25DPA_Fiber_1
)
# 遍历字典中的键
for key in ${!sample[*]};
do
echo $key ${sample[$key]}
done

# 遍历字典中的值
for value in ${samplep[*]};
do
echo $value
done

### 也可以通过定义一个含有键的数组来遍历对应的值
array=(SRR8090044 SRR8090044)
for key in ${array[@]};
do
echo ${sample[$key]}
done
```
