我有一个包含字段名称和值的CSV文件。字段名称带有'#' 例如。
#field_1,field_2,field_3
1,axt,3
2,bss,3
我需要像这样显示输出:
heading_1=field_1
heading_2=field_2
heading_3=field_3
headings=$(grep '^#' $arg_file)
echo "Fields name= $headings"
###### put a for loop to take in all headings as separate variables
for ((i=1; i<=$(echo "$headings"|tr ',' ' '|wc -w); i++))
do
echo "Trial $i field"
heading_$i=$(echo "$headings"|cut -d "," -f $i)
var="$(heading_$i)"
echo ${!var}
done
./script.sh: line 28: heading_1=#field_1: command not found
./script.sh: line 29: heading_1: command not found
如何以我想要的方式获得输出?我是shell脚本的新手,我不确定是否可能。