【问题标题】:Executing multiple sql files in a bash for loop在bash for循环中执行多个sql文件
【发布时间】:2022-07-11 22:28:43
【问题描述】:

我正在尝试在 bash 中运行以下代码行以在数据库上运行多个文件。

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

由于某种原因,它只会执行数据库上的第一个文件,而不会继续执行它们。当我检查 arrIn 中有多少文件时,它会打印两个,所以我知道有多个文件。当我运行这个时:

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}

它按预期执行这两个文件。我想在 for 循环中完成这个

【问题讨论】:

    标签: bash for-loop sqlplus


    【解决方案1】:
    #!/bin/bash
    
    arr=("0000" "1111")
    
    for i in ${arr[@]}
    do
        echo $i
    done
    
    • 您需要[@] 来循环数组中的所有项目。
    • 没有[@],它只会在第一个项目上循环,就像你经历的那样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多