Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #bash #element #array
ADD COMMENT
Topic
Name
5+4 =