The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 06-15-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
Quote:
Originally Posted by Anteus View Post
-----------

Hi thanks.. the code you gave worked.

but further while accessing the array Sam. i am having some issues.

1: When i echo ${Sam[$2]} rather than giving the 2nd element it prints all of them

2: for (( i = 0 ; i < ${#Sam[@]} ; i++ ))
do
echo ${Sam[$i]}
done
its throwing an error
Test[16]: syntax error at line 17 : `((' unexpected

can you please tell how to go about accessing the array..
We can not write a for loop like this, unless you are using awk.
I am giving an example of Array and for loop for you...

Code:
set -A _Array 1 2 3 4 5
for i in ${_Array[@]}
do
   echo $i
done