Consider the following ksh script "myquery.ksh"
#/usr/bin/env ksh -eu
PROCESS_TYP=$1
PROCESS_DT=$2
#Generate a query
makeSQL()
{
local numfiles=0
local query='SEL \\* FROM TABLE_1_'
case "$1" in
'ABC') query="${query}ABC" ; numfiles=1 ;;
'DEF') query="${query}DEF" ; numfiles=7 ;;
esac
query="${query}_V WHERE LOAD_DT='${2}';"
printf "$query\n"
eval $3="${query}"
eval $4=$numfiles
return 0
}
makeSQL $PROCESS_TYP $PROCESS_DT qry num_files
printf "QUERY: $qry\n"
printf "NUMFILES: $num_files\n"
In the above code, the eval $3="${query}" statement never works correctly. In all circumstances it seems to attempt to glob the "*" in the "local query="... statement.
./myquery.ksh ABC 2011-01-01
It always returns a message like this:
./myquery.ksh: line 17: \*: command not found
I am pretty sure this is my own user error with how I am applying eval in this situation but have tried nearly every alternate syntax construct for doing that eval $3 assignment but cannot manage to make this work.
I have tagged this as bash because I am pretty sure it would also behave identically there as well...