“bash jika elemen dalam array” Kode Jawaban

bash jika elemen dalam 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
Charles-Alexandre Roy

Periksa apakah array bash berisi nilai

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
Hutch Polecat

Jawaban yang mirip dengan “bash jika elemen dalam array”

Pertanyaan yang mirip dengan “bash jika elemen dalam array”

Lebih banyak jawaban terkait untuk “bash jika elemen dalam array” di Shell/Bash

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya