Sponsored Content
Full Discussion: Incrementing Variable Names
Top Forums UNIX for Dummies Questions & Answers Incrementing Variable Names Post 302443646 by msb65 on Monday 9th of August 2010 05:20:39 PM
Old 08-09-2010
Incrementing Variable Names

Hi,

I am using BASH. I have encountered a situation where the following is necessary (but I am not sure how to do it):

Code:
#Define multiple arrays, whose names only differ by a number:
ARRAY_1=(1 2 3)
ARRAY_2=(4 5 6)
ARRAY_3=(7 8 9)

#Define ARRAY_AMOUNT, the number of arrays. In this case ARRAY_AMOUNT is 3:
ARRAY_AMOUNT=3

#Go through a FOR loop a number of times equal to ARRAY_AMOUNT, with the variable "A" being the place setter:
for (( A=1; A=$REGION_AMOUNT; A++ )); do
        
#Set GOOD_ARRAY equal to 'ARRAY_'${A}; ie when A=1 then GOOD_ARRAY will equal ARRAY_1 which is an array containing the values 1 2 3. THIS IS WHAT I DON'T KNOW HOW TO DO:

#DOESN'T WORK:
GOOD_ARRAY='ARRAY_'${A}

echo ${GOOD_ARRAY[@]}
        
endfor

Any help is much appreciated. Thanks!

Mike
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable names

Hi I have several variables called var1, var2, var3, var4 and so on. I would like to examine the contents of the variables using a loop and a variable called num which equals a figure eg num=3 I wanted to do something like echo $var$num to display the contents of var3 (4 Replies)
Discussion started by: Bab00shka
4 Replies

2. UNIX for Dummies Questions & Answers

Variable names

Hi, I have a variable v_iteration which can equal any 3 digit number eg 001 or 926 I would like to dynamically make a new variable name up using this 3 digit number eg v_another_variable_001=fred v_another_variable_926=joe The following are examples of what I have tried ... (2 Replies)
Discussion started by: Bab00shka
2 Replies

3. Linux

Incrementing the date stored in the variable

Hi all, I have a variable with date as 20080831 . Now I want to increment it as 20080901 and so on.Is there any command for this. Please help me. thanks rameez (1 Reply)
Discussion started by: rameezrajas
1 Replies

4. Shell Programming and Scripting

Incrementing a variable is not happening

Hi All, Iam trying to increment a variable Following is the code #!/usr/bin/ksh i=1; i='expr $i+1'; echo $i; Output: expr $i+1 not able to understand why its happening in that way i was expecting result as 2... if the above method is worng .. can you help how i can get... (3 Replies)
Discussion started by: kiranlalka
3 Replies

5. Homework & Coursework Questions

Incrementing Variable resets outside of while loop

1. The problem statement, all variables and given/known data: Variable is resetting to 0 after incrementing in while loop My bit of scripting displays the current users logged in the machine. Then it reads in a specific username and displays the processes for that user. The portion that I... (3 Replies)
Discussion started by: ratzlaff
3 Replies

6. Shell Programming and Scripting

Facing problem in incrementing the variable

When I did, echo $SHELL in cmd prompt of putty, its displaying /bin/sh And in my shell script., I hav started with., #!/bin/sh and i=1; while ; do . . . i=$; (9 Replies)
Discussion started by: av_vinay
9 Replies

7. UNIX for Dummies Questions & Answers

Incrementing variable in for

Hi, want to increment a variable in a for loop like this: for (( c=$total-1; c>=0; c-- )) do if ; then maximo=$valores fi done But it gives the error: No such file or directory How can i do this only incrementing the c variable? Thanks (8 Replies)
Discussion started by: limadario
8 Replies

8. Shell Programming and Scripting

incrementing the variable name along with the data?

Hello folks. I am trying to increment my variable names to match a counter that is to be used later on... Basically, i have a for loop that lists directories (for example TEST_OS DVP_OS PROD_OS ) but this loop is not static, it may contain 3 directory once and the next run 5 directories. I... (6 Replies)
Discussion started by: Stephan
6 Replies

9. Shell Programming and Scripting

[SHELL: /bin/sh] For loop using variable variable names

Simple enough problem I think, I just can't seem to get it right. The below doesn't work as intended, it's just a function defined in a much larger script: CheckValues() { for field in \ Group_ID \ Group_Title \ Rule_ID \ Rule_Severity \ ... (2 Replies)
Discussion started by: Vryali
2 Replies

10. Shell Programming and Scripting

Passing specific and incrementing lines of text from file via variable

This is part of a larger script where I need to pass only 1 line of a file to the script, based on a variable and not a direct reference. As part of a for loop : # for((line=0;line<50;line++)); do # awk ‘NR==$line' PhraseList.txt; done ... (5 Replies)
Discussion started by: Seth
5 Replies
RTF_FILTER(3)							 rtfilter library						     RTF_FILTER(3)

NAME
rtf_filter - filters a chunk of data SYNOPSIS
#include <rtfilter.h> unsigned int rtf_filter(hfilter filt, const void *x, void *y, unsigned int ns); DESCRIPTION
This function applies the filter referenced by filt on ns samples specified by the pointer x and writes the filtered data into the array pointed by y. The arrays pointed by made of values whose correspond to the type specified at the creation of the filter. In addition, the two arrays must not overlap (failing to comply will lead to undefined results). Their number of elements have to be equal to ns multiplied by the number of channels processed (specified at the creation of the filter). The arrays should be packed by channels with the following pattern: |S1C1|S1C2|...|S1Ck|S2C1|S2C2|....|S2Ck|...|SnsCk| where SiCj refers to the data value of the i-th sample and the j-th channel and k refers to the number of channel specified at the creation of the filter. RETURN VALUE
Returns the number of samples written in the array pointer by y. For most of the filters, this value will always be equal to ns. This is however not the case of a downsampling filter whose the number of samples returned may vary from one call to another. PERFORMANCE CONSIDERATION
On platforms that support SIMD instructions, rtf_filter() is implemented in 2 different versions: one normal and one using SIMD instruction set which performs nearly 4x faster than the normal one when processing float data types. The SIMD version is automatically selected at runtime if the following conditions are met (otherwise, the implementation falls back to the normal version): - The input x and output y are aligned on 16 bytes boundary (128 bits) - The sample strides (the size of the data type multiplied by the number of channel) of the input and output are multiples of 16 bytes. The first condition is easily met by allocating x and y using memory allocation function mandating a certain alignment (for example, posix_memalign(3) on POSIX platform). The second condition is met if the number of channels is carefully chosen. Given the boost obtained with the SIMD version, it is often interesting to add unused channels into the input and output (when possible) just to make the strides multiple of 16 bytes (for example using always a multiple of 4 channels when dealing with float and real values). SEE ALSO
rtf_create_filter(3), rtf_init_filter(3) EPFL
2010 RTF_FILTER(3)
All times are GMT -4. The time now is 08:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy