假设我有以下 CSV 文件 (sample.csv)
filepath1
filepath1,filepath2
filepath1,filepath2,filepath3
filepath1,filepath2,filepath3,filepath4
filepath1,filepath2
我需要使用的程序使用以下语法:
program_im_using --file filepath1
但如果存在多个文件,输入的语法为:
program_im_using --file filepath1 --file filepath2
or
program_im_using --file filepath1 --file filepath2 --file filepath3
我要粘贴 CSV 文件中的值,如下所示:
filepath_first=( $(awk -F "\"*,\"*" '{print $1}' $sample_csv) )
filepath_second=( $(awk -F "\"*,\"*" '{print $2}' $sample_csv) )
for i in "${!filenames[@]}"; do
program_im_using --file "${filepath_first[i]}" --file "${filepath_second[i]}"
done
我所举的例子只有在每行恰好有 2 列值时才有效。我该如何概括,以便如果我有一列,我会得到:
program_im_using --file filepath1
但如果我有两个
program_im_using --file filepath1 --file filepath2
ETC?