Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

bash script language check if item in array

array=(staging prod)

if [[ ${array[*]} =~ $1 ]]; then
    echo "Supported Environment";
else
    echo "Unsupported Environment";
fi
Comment

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
Comment

PREVIOUS NEXT
Code Example
Shell :: iptables deny all 
Shell :: scp folder recursive 
Shell :: get ip of raspberry pi 
Shell :: git set origin 
Shell :: pip installation directory 
Shell :: sequelize installation 
Shell :: how to refresh cache on github 
Shell :: powershell while loop 
Shell :: how to create a host driver in docker 
Shell :: show internet password 
Shell :: gitbash shortcut to clear the terminal 
Shell :: install spicetify on windows 
Shell :: enable rdp windows 10 powershell 
Shell :: install redux npm 
Shell :: ubuntu disable ssh root 
Shell :: clone commit of a branch 
Shell :: date fns install 
Shell :: how to install terraform macos 
Shell :: git version 
Shell :: mac install sklearn 
Shell :: how to get ips of any website 
Shell :: git cherry pick 
Shell :: lines of code 
Shell :: gitignore io 
Shell :: linux list environment variables 
Shell :: hugo build 
Shell :: linux count number of times word appears in file 
Shell :: how to install sublime text 3 on ubuntu 20.04 
Shell :: update git repository 
Shell :: blackeye bash 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =