Skip to main content
added 48 characters in body
Source Link
ilkkachu
  • 148.2k
  • 16
  • 268
  • 441

I have an array like: moduleList=(AB, ABCdef, ABCd)

moduleList=(AB, ABCdef, ABCd)

My array is numerically-indexed array not an associative array. I want to do an exact match for each element in array and to perform certain tasks.

Currently I'm doing like: if [[ ${moduleList["AB"]} ]]; then #do this. fi

if [[ ${moduleList["ABCdef"]} ]]; then #do that. fi

if [[  ${moduleList["AB"]}  ]]; then
    #do this.
fi



if [[  ${moduleList["ABCdef"]}  ]]; then
    #do that.
fi

But both the conditions are getting true as "AB""AB" is there in each word. How can I distinguish each condition based on an exact match.

I have an array like: moduleList=(AB, ABCdef, ABCd)

My array is numerically-indexed array not an associative array. I want to do an exact match for each element in array and to perform certain tasks.

Currently I'm doing like: if [[ ${moduleList["AB"]} ]]; then #do this. fi

if [[ ${moduleList["ABCdef"]} ]]; then #do that. fi

But both the conditions are getting true as "AB" is there in each word. How can I distinguish each condition based on an exact match.

I have an array like:

moduleList=(AB, ABCdef, ABCd)

My array is numerically-indexed array not an associative array. I want to do an exact match for each element in array and to perform certain tasks.

Currently I'm doing like:

if [[  ${moduleList["AB"]}  ]]; then
    #do this.
fi



if [[  ${moduleList["ABCdef"]}  ]]; then
    #do that.
fi

But both the conditions are getting true as "AB" is there in each word. How can I distinguish each condition based on an exact match.

Source Link
BMD
  • 113
  • 4

Exact string search in array

I have an array like: moduleList=(AB, ABCdef, ABCd)

My array is numerically-indexed array not an associative array. I want to do an exact match for each element in array and to perform certain tasks.

Currently I'm doing like: if [[ ${moduleList["AB"]} ]]; then #do this. fi

if [[ ${moduleList["ABCdef"]} ]]; then #do that. fi

But both the conditions are getting true as "AB" is there in each word. How can I distinguish each condition based on an exact match.