Answers for "check if an element is in an array bash"

1

Check if a Bash array contains a value

if [[ " ${array[*]} " =~ " ${value} " ]]; then
    # whatever you want to do when array contains value
fi

if [[ ! " ${array[*]} " =~ " ${value} " ]]; then
    # whatever you want to do when array doesn't contain value
fi
Posted by: Guest on August-22-2021

Code answers related to "check if an element is in an array bash"

Browse Popular Code Answers by Language