this is my array:
orlist=""
orlist="T_TAB1 \n"
orlist=$orlist"T_TAB2 \n"
orlist=$orlist"T_TAB3 \n"
orlist=$orlist"T_TAB4 \n"
echo $orlist
arrIdx=0
OLD_IFS=$IFS;
IFS="\n"
for IndixList in ${orlist[@]};
do
echo $IndxList
MYDIR[${arraryIndix}]=$IndixList
(( arraryIndix = $arraryIndix+ 1 ))
done
IFS=$OLD_IFS
i have to do a SELECT in a oracle db inside a for loop so i have to read the $orlist tab by tab. I've tried this but doesn't work it takes the whole array not tab by tab:
for arraryIndix in ${orlist[@]};
do
echo "SET HEADING OFF" >> ${FILEOR_SQL}
echo "SET TERMOUT OFF" >> ${FILEOR_SQL}
echo "SET PAGESIZE 0" >> ${FILEOR_SQL}
echo "SET LINESIZE 1000" >> ${FILEOR_SQL}
echo "SET FEEDBACK OFF" >> ${FILEOR_SQL}
echo "SET TRIMSPOOL ON" >> ${FILEOR_SQL}
echo "SPOOL ${FILE_DAT}" >> ${FILEOR_SQL}
echo "SELECT * " >> ${FILEOR_SQL}
echo "FROM ${orlist[@]}" >> ${FILEOR_SQL}
echo "WHERE REP_ARG = 2; " >> ${FILEOR_SQL}
echo "SPOOL OFF" >> ${FILEOR_SQL}
echo "COMMIT;" >> ${FILEOR_SQL}
echo "SET HEADING ON" >> ${FILEOR_SQL}
echo "SET TERMOUT ON" >> ${FILEOR_SQL}
echo "SET PAGESIZE 14" >> ${FILEOR_SQL}
echo "SET FEEDBACK ON" >> ${FILEOR_SQL}
echo "SET TRIMSPOOL OFF" >> ${FILEOR_SQL}
echo "EXIT;" >> ${FILEOR_SQL}
sqlplus -S -L ${Connection} @${FILEOR_SQL} #connection is a var for connect with `sqlplus`
done
Any suggestions? Thanks in advance
Well your problem came because if you write
\n
, it's not necessarily treated as a new line, somebody have to translate the sequence of\
followed byn
as a newline. also same inIFS="\n"
IFS needs to be set to something which evaluates to a newline, not a combination of\
andn
. Also orlist is a variable, you have not used it as an array, and at the for loop, it is not going to be treated as an array. I did some changes and it seemed to work fineOutput
Update following comments
Instead of invoking sqlplus many times, make the SQL script contain all the queries: