Skip to content

Instantly share code, notes, and snippets.

View Dup4's full-sized avatar

Duplicate4 Dup4

View GitHub Profile
@Dup4
Dup4 / t.sh
Created October 16, 2020 03:25 — forked from likohank/t.sh
shell 判断某个元素是否在数组中,查看某个key是否存在
if [[ " ${array[@]} " =~ " ${value} " ]]; then
# whatever you want to do when arr contains value
fi
------------------------------------------------------
if [[ ! " ${array[@]} " =~ " ${value} " ]]; then
# whatever you want to do when arr doesn't contain value
fi
------------------------------------------------------
if [[ " ${!array[@]} " =~ " ${value} " ]]; then
# whatever you want to do when arr contains value