Operating System - HP-UX
1830899 Members
2910 Online
110017 Solutions
New Discussion

Re: How to define variable ranges like a=20..40 using ksh

 
SOLVED
Go to solution
ashanabey
Advisor

How to define variable ranges like a=20..40 using ksh

Hi

I need to assign value with in the number range,how to assign to the variable.?

number_range_like=20...40 , selected range number is 15 and variable shoed hold value 15.

Can any one help.

Thanks
Ashan
legend the heart and lend the hand
8 REPLIES 8
Bharat Katkar
Honored Contributor

Re: How to define variable ranges like a=20..40 using ksh

This should work :


number_range_like = [ value1,value2,...,valuen ]
You need to know a lot to actually know how little you know
Mark Philip L. Castro
Occasional Advisor

Re: How to define variable ranges like a=20..40 using ksh

How are you going to use it? Maybe you can have a different approach.
Sanjay Kumar Suri
Honored Contributor
Solution

Re: How to define variable ranges like a=20..40 using ksh

Is this what you need?

test[0]=20
test[1]=21
test[2]=22
test[3]=40
echo ${test[*]}

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
ashanabey
Advisor

Re: How to define variable ranges like a=20..40 using ksh



Hi Bharat,

How to pick a value from the range and assign
to variable.

num_range="[1, 2, 3, 4, 5 ]" I need select only and test value 2 and 5 and result will
assign to logical condition.

how to do t his

Thanks

Ashan




legend the heart and lend the hand
Laurent Menase
Honored Contributor

Re: How to define variable ranges like a=20..40 using ksh

Hi Do you mean a random value?

typeset -i x
typeset -i minrange=20
typeset -i maxrange=40


x=$RANDOM*(maxrange-minrange)+minrange
it will pick a random value in [minrange,maxrange[ interval


Mark Philip L. Castro
Occasional Advisor

Re: How to define variable ranges like a=20..40 using ksh

Ashan,

You can just use positional values by using "cut" command.

Example:
$ numer_range_like="1,2,3,4,5"
$ echo ${number_range_like} | read second fifth

To see the values:
$ echo $second
$ echo $fifth


FYI,
Mark
Mark Philip L. Castro
Occasional Advisor

Re: How to define variable ranges like a=20..40 using ksh

Ashan,

You can just use positional values by using "read" command.

Example:
$ numer_range_like="1,2,3,4,5"
$ echo ${number_range_like} | read second fifth

To see the values:
$ echo $second
$ echo $fifth


FYI,
Mark
Mark Philip L. Castro
Occasional Advisor

Re: How to define variable ranges like a=20..40 using ksh

Ashan,

Sorry, command was incomplete.

You can just use positional values by using "cut" command.

Example:
$ numer_range_like="1,2,3,4,5"
$ echo ${number_range_like} | tr -s "," " " | read second fifth

To see the values:
$ echo $second
$ echo $fifth


FYI,
Mark