0

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

1 Answer 1

1
#!/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.
Sign up to request clarification or add additional context in comments.

2 Comments

You forgot to double quote "${arr[@]}"
Indeed, fixed, thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.