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 :: mac os uninstall oh my zsh 
Shell :: yarn run ios device 
Shell :: @react-navigation/stack install 
Shell :: git add missed to last commit 
Shell :: ubuntu remove package and dependencies install deb 
Shell :: install csfml on ubuntu 
Shell :: find which service is using port 
Shell :: kubectl scale deployment 
Shell :: which user apache runs as ubntu 
Shell :: if argument supplied bash 
Shell :: enable setting in ubuntu 
Shell :: extract tar.gz mac command line 
Shell :: uninstall packages linux terminal 
Shell :: install next globally 
Shell :: pipreqs not working 
Shell :: make fish as default shell 
Shell :: kill process for port 
Shell :: python3 install mutagen 
Shell :: delete conda from machine 
Shell :: weka ubuntu 
Shell :: update npm-windows 
Shell :: git abort REVERTING 
Shell :: how to find the ~/.zshrc file 
Shell :: Start / Restart / Stop Nginx Commands 
Shell :: git discard local changes 
Shell :: libqt5x11extras5 install ubuntu 
Shell :: ifconfig not found ubuntu 20.04 
Shell :: how to reset kali keyring 
Shell :: conda install moviepy 
Shell :: activate git case sensitive windows 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =