#!/bin/bash
## arrays
## author: Xiaoxu Guan at LSU HPC.
## Jan 30, 2016

echo

# format 1
my_array=("John" "Cox" "is" "my" "friend" "." )

echo ${my_array[@]}
unset my_array

# format 2
my_array=(John Cox is my friend .)

echo ${my_array[@]}

noelement=${#my_array[@]}


echo "No of the array element is "  $noelement

let nmax=$noelement-1

for i in `seq 0 $nmax`
do
  echo "i = $i"  ${my_array[$i]}
done

# add the other element
my_array[10]="That's good!"

echo ${my_array[@]}

echo "No of the array element is "  ${#my_array[@]}


# delete one of the elements
del=( "Cox" )  ###  try del=( $my_array[1] )
my_newarray=( "${my_array[@]/$del}" )

echo ${my_newarray[@]}

echo "No of the array element is "  ${#my_newarray[@]}

echo

echo ${my_newarray[0]}
echo ${my_newarray[1]}
echo ${my_newarray[2]}
echo ${my_newarray[3]}
echo ${my_newarray[4]}

echo
