0

i made a function to parse my array. i've to send back two variable -"$y" there is a match -"$value" the name of the value

i dont understand why he dont want to initialize my res variable to y ?

 function contains() {
    local n=$#
    local value=${!n}
    for ((i=1;i < $#;i++)) {
        if [ "${!i}" == "${value}" ]; then
             res= "y" 
             echo "value of y : $res"
             echo "$res|$value" 
            return 0
        fi
    }   
    echo "no match found function"
    return 1
}



++ '[' 2017-11-16 == 2017-11-16 ']'
++ res=
++ y
./connectOracle.sh: line 53: y: command not found
++ echo 'value y : '
john_doe
  • 13
  • 2
  • 2
    Do `res="y"`. Remove the space after the = sign. – Nic3500 Nov 27 '17 at 16:20
  • 1
    https://stackoverflow.com/questions/2268104/command-not-found-error-in-bash-variable-assignment/2268117#2268117 – William Pursell Nov 27 '17 at 16:21
  • Consider making a habit of running your code through http://shellcheck.net/ before asking questions here. – Charles Duffy Nov 27 '17 at 16:28
  • thanks i didn't see it :( – john_doe Nov 27 '17 at 16:29
  • i dont understand why in my second function he dont receive my res params ? if [[ $(contains "${arr[@]}" "$MEDIA_NDATE") == $1 ]]; then echo "match found $2 " – john_doe Nov 27 '17 at 16:30
  • Your function doesn't print the value of `"$1"` so the condition is false. It's not entirely clear what you are attempting to do; maybe post a new question to explain what you are trying to do and where it is failing. – tripleee Nov 27 '17 at 16:44

0 Answers0