I have a variable animals.
animals=lion*tiger*elephant**cat***dog
I just want to split by the delimiter * and store it into an array.
Expected:
animals[0]="lion"
animals[1]="tiger"
animals[2]="elephant"
animals[3]=""
animals[4]="cat"
animals[5]=""
animals[6]=""
animals[7]="dog"
I used awk command but I don't know how to store empty string for no value.
echo "$(awk -F* '{ for (i = 1; i <= 8; i++) print $i }' <<< "$animals")"
Result:
lion
tiger
elephant
cat
dog
Array:
Array=($(awk -F* '{ for (i = 1; i <= 8; i++) print $i }' <<< "$animals"))
# Null values get neglected