0

I'm trying to assign a value if the array at a certain index is empty, but I'm getting a command not found error.

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

this code is working except for the "value assign part":

# if empty set Not Available
if [[ -z ${array[6]} ]] ; then
        $array[6]="Not Available"
        echo barcode is ${array[6]}
fi

Error:

./convert-csv-to-xml: row 20: LM113A[6]=Not Available: command not found
barcode is

row 20 is:

$array[6]="Not Available"

1 Answer 1

0

We don't need to use $ for assigning a string to an array.

Just try with

array[6]="Not Available"
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.