Horje
bash if element in array Code Example
bash if element in array
# Basic syntax:
if [[ "${array[*]}" =~ "${value}" ]]; then
    echo "$value is in array"
fi
# Note, relative to e.g. Python, this syntax feels a little backwards. It
#	checks if the value variable is in the array, which reads right to left.
# Note, if you want to check whether the element is not in the array, use:
if [[ ! "${array[*]}" =~ "${value}" ]]; then
    echo "$value is not in array"
fi
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




Shell

Related
ackage configuration file provided by "Eigen3" with any Code Example ackage configuration file provided by "Eigen3" with any Code Example
install and use beego easily Code Example install and use beego easily Code Example
git orphan branch and remove all data Code Example git orphan branch and remove all data Code Example
docker image get extract dockerfile Code Example docker image get extract dockerfile Code Example
mariadb galera cluster exists on first sync Code Example mariadb galera cluster exists on first sync Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
19