Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

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

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:

file1=${arrIN[0]}
file2=${arrIN[1]}    
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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

#!/bin/bash

arr=("0000" "1111")

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading