
특정 인덱스의 배열이 비어 있으면 값을 할당하려고 하는데 오류가 발생합니다 command not found
.
while IFS=$';' read -r -a array
do
# if empty set Not Available
if [[ -z ${array[6]} ]] ; then
$array[6]="Not Available"
echo barcode is ${array[6]}
fi
echo ' <Product>' >> $file_out
echo ' <Reference>'${array[0]}'</Reference>' >> $file_out
echo ' <Name>'${array[1]}'</Name>' >> $file_out
echo ' <Category>'${array[2]}'</Category>' >> $file_out
echo ' <Price>'${array[3]}'</Price>' >> $file_out
echo ' <Scale>'${array[4]}'</Scale>' >> $file_out
echo ' <Manufacture>'${array[5]}'</Manufacture>' >> $file_out
echo ' <Barcode>'${array[6]}'</Barcode>' >> $file_out
echo ' <DatePub>'${array[7]}'</DatePub>' >> $file_out
echo ' <Image>'${array[8]}'</Image>' >> $file_out
echo ' <Availability>'$availability'</Availability>' >> $file_out
echo ' <Supplier>'$Supplier'</Supplier>' >> $file_out
echo ' </Product>' >> $file_out
done < $file_in
이 코드는 "값 할당 부분"을 제외하고는 잘 작동합니다.
# if empty set Not Available
if [[ -z ${array[6]} ]] ; then
$array[6]="Not Available"
echo barcode is ${array[6]}
fi
실수:
./convert-csv-to-xml: row 20: LM113A[6]=Not Available: command not found
barcode is
20번째 줄은 다음과 같습니다:
$array[6]="Not Available"
답변1
$
배열에 문자열 할당을 사용할 필요가 없습니다 .
시도 해봐
array[6]="Not Available"