0

I have this:

ql_match_arg(){
    declare -a my_array=$1
    for var in "${my_array[@]}"; do
        if [[ "$var" == "$2" ]]; then
          return 0;
        fi
    done
}


ql_ls () {
   local my_array=( "$@" ); ql_json=$(ql_match_arg my_array[@] '--json' && echo "yes")
   ql_pid="$$" ql_json="$ql_json" ql_node_ls_all
}

what I am trying to do is create a helper function (ql_match_arg) which can be used by other functions to determine in any argument matches a given name. In this case, I want to find out if the --json flag is passed as any argument to ql_ls.

The problem I have is that it's not looping over my_array - something is wrong with my code - either I am not passing the array to ql_match_arg correctly, or something else is wrong.

1

1 Answer 1

1

The problem I have is that it's not looping over my_array

With this:

declare -a my_array=$1

You are creating an array with just one value: $1, the first argument passed to your script. So there is not much to loop over there.

If you want all arguments, try:

declare -a my_array=$@

Instead.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .