sh shell user input and stote it to a array

Dear Friends,

I am doing a sh shell script , But I dont have any idea how to read value from user Keyboard and store them to an array .. Is it possible or not I am not also sure in sh shell script ?
EX:-
#! /bin/sh

read DATA
echo "DATA[1] -" $DATA[1]
echo "DATA[3] -" $DATA[2]
echo "DATA[3] -" $DATA[3]

if my input line is - 300 200 100. Then it should display

DATA[1] -300
DATA[2] -200
DATA[3] -100

If it can be store in array then is $# will give me total no of array or anything else ?
or The only way to store is
read DATA[1] DATA[2] DATA[3] in sh script ?

I need a drop of Knowledge from you friends..

Thanks in advance.
user_prady

something like this,

echo "300 200 100" | awk '{ split($0, arr, " "); for ( i in arr ) { print arr } }'

Oh oh..
But I think you did not get my problem..

Anyway Thanks for the reply

Like in csh shell script

#!/bin/csh -f

echo 'enter a line'
set userline = $<
echo $userline
set uline = ($userline)
echo $uline[1]
echo $uline[2]
echo $uline[3]
echo $uline[4]

If We enter 20 10 30 70
and I guess $# will give me total no index in that array..
Then it ll display
20
10
30
70
like this I want in sh shell script not in awk or nawk . I am not sure it is possible or not ?

Hope this time my explanation is better than before

Thanks again
user_pradyu

sh does not have support for arrays but ksh does.

Thanks for your reply...
can I have a ksh code for the above problem ?

OK, here is an example.

#!/bin/ksh

set -A parms $*
print "You supplied ${#parms[@]} parameters:"

echo 'Enter a line'
read x
echo 'You entered this line: ' $x
set -A rarray $x
print "You entered ${#rarray[@]} items"
print ${rarray[0]}
print ${rarray[1]}
print ${rarray[2]}

Thaaaaaaaaaaak You ..............Love the people out here.. :slight_smile:

The equivalent sh code is

declare -a my_array
//take user input
// store in variable/filre
//if variable then
my_array=( "variable")
//if file then
my_array=(`cat file`)

//itarate array for values