gpt4 book ai didi

linux - 检查字符串索引是否存在

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:15:29 24 4
gpt4 key购买 nike

例如,我们如何检查数组中是否存在字符串索引

declare -A SArray
SArray[a]="a"
SArray[b]="b"

read index

现在在索引上,我想检查 SArray 中是否存在索引

最佳答案

#!/bin/bash

declare -A SArray
SArray[a]="a"
SArray[b]="b"
read index

if test "${SArray["$index"]+isset}"; then
echo "index $index exists for SArray"
else
echo "no index $index for SArray"
fi

关于linux - 检查字符串索引是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30866817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com