Executing multiple sql files in a bash for loop

I’m trying to run the following lines of code in bash to run multiple files on a database.

for file in ${arrIN}; do
    echo "Executing ${file}..";
    sqlplus ${db_user}/${db_password}@${db_host}:1521/${db_sid} @${file};

For some reason, it will only execute the first file on the database, but won’t keep executing them. When I check how many files are in arrIn it prints two, so I know there are multiple files. When I run this:

sqlplus ${db_user}/${db_password}@${db_host}:1521/${db_sid} @${file1}
sqlplus ${db_user}/${db_password}@${db_host}:1521/${db_sid} @${file2}

It executes both files as expected. I would like to acomplish this in a for loop

>Solution :


arr=("0000" "1111")

for i in ${arr[@]}
    echo $i
  • you need [@] to loop on all the items in the array.
  • without [@], it just loops on the first item, like you experienced.

Leave a Reply