Bash split string into array

view full story

http://www.linuxforums.org – Hi, I have a string which is an IP Address, I want to spli the octets into an array and retrieve the individual octets. Here is what I have got so far: Code: # create the string IP address IPSTR="" # declare the array declare -a IPARR IP_ARR=$(echo $IPSTR | tr "." " ") # print out the first octet (should be 192). This actually prints out a blank line echo ${IPARR[0]} # also tried with quotes, but same result: echo "${IPARR[0]}" I can print the entire array out with this line of code: Code: echo ${IPARR[@]} I can also loop through the array and print out the octets one by one. But I want to be able to access them directly without having to loop. Anyone know why it prints out a blank line when I try to access an array element? (HowTos)