Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Initializing an array with a number of 0'es

Status
Not open for further replies.

Larshg

Programmer
Mar 1, 2001
187
DK
Hi

I want a script that initializes an array with a number of 0 (the length of the array is given as a parameter)

normaly I would do something like this

set -A zerros `echo "0 0 0 0 0 0 0 0 0"`

But I need a way to make the array the length of the parameter given to the script and make alle the places in the array 0

thanks

Larshg
 
In ksh try something like this:
Code:
# $1 = length of array
i=0; tmp=""
while [ $i -lt $1 ]; do
  tmp="0 $tmp"
  i=$((1+i))
done
set -A zerros $tmp

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top