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.
ksh. Is the shell you are using the Korn shell? – Kusalananda Sep 03 '23 at 05:12iis 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 theif (( i == 0 ))into afindCommandfunction, that would still make no sense. That0${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$monthexpansions to be 0-left-padded to a length of 2, you can declare it astypeset -Z2 month. – Stéphane Chazelas Sep 03 '23 at 09:56