I have a strange issue with array manipulation within a bash script on Solaris. I am using the syntax ${varName[@]:index}
to obtain all of the elements in array varname after the specified index. However, if there is only one element after the specified index, nothing is returned.
This can be easily demonstrated by example:
#!/bin/bash
paramArray=( a b c )
echo "everything after 2" ${paramArray[@]:2} # Should display c but doesn't
echo "parameter 2 only " ${paramArray[2]} # Correctly displays c
paramArray=( a b c d e )
echo "everything after 2" ${paramArray[@]:2} # Correctly displays c d e
echo "parameter 2 only " ${paramArray[2]} # Correctly displays c
This code works correctly on a Windows box running Cygwin, but fails on Solaris (version: Solaris 9 9/05 s9s_u8wos_05 SPARC)
Can anyone explain this behaviour?