#!/bin/bash

#
# Test created by David B. Anderson dbanders @ gmail dot com
#

echo "Testing with: " 
bash --version

echo " "
echo "Testing bash array declare using the output of a subshell that contains control A characters."
t='mhost110.2.2.12/10.2.2.11TCP000ALIVE200000000010.2.2.1110.2.2.121
mhost1/dev/ttyS1TTY38400349350ALIVE0020000204541645384(null)(null)99
'

declare -a COM=($(echo $t | head -n1 | awk -F'' '{print $1,$2,$3}'))
echo "COM 0: should be 'mhost1'              is '${COM[0]}'"
echo "COM 1: should be '10.2.2.12/10.2.2.11' is '${COM[1]}'"
echo "COM 2: should be 'TCP'                 is '${COM[2]}'"

if [ "x${COM[0]}" != "xmhost1" ]; then
    echo "TEST: FAILED"
else
    echo "TEST: PASSED"
fi

echo ""
echo "Testing bash array declare using the output of a subshell that contains is the same as above with ':' instead of control A characters."
t1='mhost1:10.2.2.12/10.2.2.11:TCP:0:0:0:ALIVE:2:0:0:0:0:0:0:0:0:0:10.2.2.11:10.2.2.12:1
mhost1:/dev/ttyS1:TTY:38400:349:350:ALIVE:0:0:2:0:0:0:0:20:48892:48812:(null):(null):99'

declare -a COMC=($(echo $t1 | head -n1 | awk -F: '{print $1,$2,$3}'))
echo "COMC 0: should be 'mhost1'              is '${COMC[0]}'"
echo "COMC 1: should be '10.2.2.12/10.2.2.11' is '${COMC[1]}'"
echo "COMC 2: should be 'TCP'                 is '${COMC[2]}'"

if [ "x${COMC[0]}" != "xmhost1" ]; then
    echo "TEST: FAILED"
else
    echo "TEST: PASSED"
fi
