0

I have this code:

        if (( i == 0 )); then
            findCommand="find . -name \"${id}*0${month}*\" | sort -r | head -1"
        else
            findCommand="find . -name \"${id}*0${month}*\""
        fi
    while read fileName; do
        data[i]=$(sed -n -f sed_script "${fileName}")
        trim=${fileName#./* }
        period[i]=${trim%.json}
    done < <(${findCommand})

My problem with it is that the process substitution is returning nothing, I supose It has to do with the wildcard expansion but I have no idea how to properly escape the findCommand string so that the wildcard expansion is properly done.

Edit: eval command does the trick.

  • You have tagged your question with ksh. Is the shell you are using the Korn shell? – Kusalananda Sep 03 '23 at 05:12
  • To store code, use a function, not a variable. But even then your script doesn't make much sense. It looks like i is meant to be an index in the arrays but you're not incrementing it. The find command is also run only once and you're looping over its output. Even if you moved the if (( i == 0 )) into a findCommand function, that would still make no sense. That 0${month} sounds like it's going to break in Oct/Nov/Dec. What exactly are you trying to do? – Stéphane Chazelas Sep 03 '23 at 06:47
  • btw, if you want $month expansions to be 0-left-padded to a length of 2, you can declare it as typeset -Z2 month. – Stéphane Chazelas Sep 03 '23 at 09:56

0 Answers0