## array in bourne shell

### array in bourne shell

How does one mske an array in bourne shell

thanks

Also if one could point me to a good bourne shell site it would be great.

Bibek

### array in bourne shell

Quote:> How does one make an array in bourne shell

The Bourne shell doesn't support arrays.

--

See another pointless homepage at <URL:http://home.pages.de/~naddy/>.

### array in bourne shell

> How does one mske an array in bourne shell

> thanks

> Also if one could point me to a good bourne shell site it would be great.

> Bibek

In bourne you have to use eval to index variables. Here is an example
which uses an array of month names to determine the month previous to
this one.

#!/bin/sh

mth1=Jan
mth2=Feb
mth3=Mar
mth4=Apr
mth5=May
mth6=Jun
mth7=Jul
mth8=Aug
mth9=Sep
mth10=Oct
mth11=Nov
mth12=Dec

# What is the index of the current month (1-12)?

idx=`date +%m`

# What was the index last month?

idx=`expr \$idx - 1`
if [ "\$idx" -eq 0 ]
then
idx=12              # I get confused doing modulus arithmetic
fi

# Map the new index to a name
#
# Note that eval takes its arguments and treats them as input to
# the shell. This allows us to expand the variable name in two
# stages: the first (as an argument to eval) expands %idx, the
# second (as input to the shell) assigns to monthname the value
# held by the variable with the name compounded from "mth" and
# "\$idx". Neat huh?
#
# Would be even better if the shell supported the following:
#
#    monthname=\${mth\$idx}
#
# but nested variable names are not supported

eval monthname=\\$mth\$idx

echo "last month: \$monthname"

--

Regards,

Bruce

+--------------------------------------------------------------------------+
| Bruce Fountain                 NEC Australia - New Product Development   |

+--------------------------------------------------------------------------+

### array in bourne shell

> How does one mske an array in bourne shell

> thanks

> Also if one could point me to a good bourne shell site it would be great.

> Bibek

Use GNU bash. It supports array and many other good things

Hi All,

I am wondering that if anyone knows how to convert the C shell
array to Bourne shell?

Or anyone knows where can I find the code to convert C shell array
to Bourn shell on the web?

#  Replace arg6 in array with the partition size