array in bourne shell

array in bourne shell

Post by Bibek Shresth » Thu, 26 Feb 1998 04:00:00



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

Post by Christian Weisgerb » Fri, 27 Feb 1998 04:00:00




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

Post by Bruce Fountai » Sat, 28 Feb 1998 04:00:00



> 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

Post by Grigoriy Stroki » Sun, 01 Mar 1998 04:00:00



> 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
 
 
 

1. Convert C shell array to Bourne shell

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

Thank you for your time.

################################################################################
Sun Microsystem Computer Company

Sophia Cheng                        415-336-5067

################################################################################

2. Benchmarks

3. Light Speed Bourne Shell! (was: Bourne shell tricks)

4. Exported symbols...

5. 1D-Arrays in Bourne shell

6. Linux Network

7. array in bourne shell

8. Change default whois server

9. Need help on bourne shell arrays...

10. Array and looping in Bourne Shell

11. creating an array in the Bourne shell

12. How do I make/use bourne shell array variables?

13. array in bourne shell