从逗号分隔的文件中读取值并使用 shell 脚本在循环中传递值

reading values from a comma separated file and passing the values in loops using shell script

我有一个配置文件,其中包含如下逗号分隔值。

jobA,table1,table2,table3
jobB,table4,table5,table6,table7
jobC,table8,table9

现在我想读取第 1 行的第一列,即一个变量中的 $1(jobA) 和单独变量中相应作业的所有表(table1、table2、table3)作为列表,并将此列表迭代到环形。类似的事情应该一直持续到文件结束即 jobN ..我尝试了下面的代码但没有成功。我是新手任何建议都会很有帮助。

#!/bin/bash
JOBS=$(awk -f\, '(print }' a.config)
declare -p JOBS
for jobs in "${List[@]}"
  do
    if [[somecondition]];then
    else
    fi
    TABLES=$(awk -f\, '{for(i=2;i<=NF;++i)print $i}' a.config)
    declare -p TABLES
    for tables in ${list[@]}
      do
        if [[somecondition]];then
        else
        fi
    done 
done
exit 0;
while read line; do
    job_name=$(echo "$line"|awk 'BEGIN{FS=","}{print }')
    echo "JobName is $job_name"
    # remove the jobname from the string
    tablestring=${line#"$job_name"}
    # Iterate over the remaining string
    for table in ${tablestring//,/ }; do
        echo $table
    done
done<jobfile

输出:

$ bash script.sh
JobName is jobA
table1
table2
table3
JobName is jobB
table4
table5
table6
table7
JobName is jobC
table8
table9