Sponsored Content
Top Forums Shell Programming and Scripting Need help with array substitution Post 303000203 by zaxxon on Thursday 6th of July 2017 08:16:30 AM
Old 07-06-2017
See my comment in your post on using "urgent" in the topic, thanks.

Your first script uses ksh syntax to declare an array with set -A. In your second script you use a shebang to call bash, which has a different syntax to declare an array like:
Code:
$ declare -a myarray=(eins zwei drei)
$ echo ${myarray[1]}
zwei

#or

$ myarray=(eins zwei drei)
$ echo ${myarray[2]}
drei


Last edited by zaxxon; 07-06-2017 at 09:28 AM.. Reason: added examples
This User Gave Thanks to zaxxon For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Array help (variable substitution).

I am using an array (clmlist01). I have 61 of these and have 4 or more references to each one in a block of code that I do not want to have to hardcode. With that being said, I am creating a varible and going through a for loop to create the actually name of each array. The arrays would end up... (3 Replies)
Discussion started by: dsimpg1
3 Replies

2. Programming

Creating an array to hold posix thread ids: Only dynamic array works

I am facing a strange error while creating posix threads: Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output. Snippet 1 This works: -------------- int *threadids; threadids = (int *) malloc (num_threads * sizeof(int)); ... (4 Replies)
Discussion started by: kmehta
4 Replies

3. Shell Programming and Scripting

Tricky array substitution in functions

Hello, Please tell me if there is a better way to get the number of elements from an array that is passed to a function. This is what works on Solaris 8 (ksh) but it looks odd: loop_array() { array_name=$2 b1='\${\#' b2='}' nr_elements=`eval echo... (6 Replies)
Discussion started by: majormark
6 Replies

4. Shell Programming and Scripting

Difference between "Command substitution" and "Process substitution"

Hi, What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution? while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file But, while IFS='\n' read -r... (3 Replies)
Discussion started by: royalibrahim
3 Replies

5. Shell Programming and Scripting

Array reference - bad substitution

I've created a series of arrays named as follows: row1 row2 row3 . . . row10 Each has 4 elements. I'm trying to echo the array elements out in a for loop. Here's what I have: for ((i=1;i<=10;i++)) do for ((j=1;j<=4;j++)) do eval out=${row`echo $i`} echo -n $out (3 Replies)
Discussion started by: swankgd
3 Replies

6. Shell Programming and Scripting

Substitution in a file dont work with an Array in filename

Hi. I´ve a script that should substitude the 8th line in a file called xxx.num6. The "xxx" is set by an array filled with this command: j=0 for Par in *.sys ; do Par=`echo $Par | sed 's/\(.*\).sys/\1/'` ; Par2="$Par" ; echo "${Par2}" j=$((j + 1)); done Now i try... (0 Replies)
Discussion started by: Lock3
0 Replies

7. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

8. Shell Programming and Scripting

Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help. pesudo code if == ENDSINFIVEINTS ]]; then do... (4 Replies)
Discussion started by: briandanielz
4 Replies

9. Shell Programming and Scripting

Variable substitution in array printing

Hi folks, A really dumb question as I've wasted far too long trying to get this to work.... (on RH bash) I have an array: m0='<hello>' m0='<there>' m0='<fred>' v0='<goodbye>' v0='<again>' v0='<john>' in my code I calculate the value of the variable to output and if I echo it, I... (2 Replies)
Discussion started by: say170
2 Replies

10. Shell Programming and Scripting

Bash arrays: rebin/interpolate smaller array to large array

hello, i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N. for case 1, I want to stretch N to fit M arrayHuge H = (... (2 Replies)
Discussion started by: f77hack
2 Replies
MAKEDUMPFILE.CONF(5)					Linux System Administrator's Manual				      MAKEDUMPFILE.CONF(5)

NAME
makedumpfile.conf - The filter configuration file for makedumpfile(8). DESCRIPTION
The makedumpfile.conf is a configuration file for makedumpfile tool. makedumpfile.conf file contains the erase commands to filter out desired kernel data from the vmcore while creating DUMPFILE using makedumpfile tool. makedumpfile reads the filter config and builds the list of memory addresses and its sizes after processing filter commands. The memory locations that require to be filtered out are then poi- soned with character X (58 in Hex). FILE FORMAT
The file consists of module sections that contains filter commands. A section begins with the name of the section in square brackets and continues until the next section begins. "["<ModuleName>"]" <FilterCommands> where "[" is the character [ "]" is the character ] <ModuleName> is either 'vmlinux' or name of a Linux kernel module. <FilterCommands> is a list of one or more filter commands as described in the section FILTER COMMANDS of this manual page. The section name indicates a kernel module name (including vmlinux) where the symbols specified in subsequent erase commands belong to. The unnamed section defaults to [vmlinux] section. However, a user can also explicitly define [vmlinux] section. The sections help makedumpfile tool to select appropriate kernel or module debuginfo file before processing the subsequent erase commands. Before selecting appropriate debuginfo file, the module name is validated against the loaded modules from the vmcore. If no match is found, then the section is ignored and makedumpfile skips to the next module section. If match is found, then makedumpfile will try to load the corresponding module debug- info file. If module debuginfo is not available then, makedumpfile will skip the section with a warning message. FILTER COMMANDS
filter command A filter command is either an erase command or a loop construct. Each erase command and loop construct must start with a new line. Each filter command describes data in the dump to be erased. Syntax: <EraseCommands>|<LoopConstruct> where <EraseCommands> Described in the subsection erase command of this manual page. <LoopConstruct> Described in the subsection Loop construct of this manual page. erase command Erase specified size of a kernel data referred by specified kernel/module symbol or its member component. The erase command syntax is: erase <Symbol>[.member[...]] [size <SizeValue>[K|M]] erase <Symbol>[.member[...]] [size <SizeSymbol>] erase <Symbol>[.member[...]] [nullify] where <Symbol> A kernel or module symbol (variable) name that is part of global symbols /proc/kallsyms. <SizeValue> A positive integer value as a size of the data in bytes to be erased. The suffixes 'K' and 'M' can be used to specify kilobytes and Megabytes respectively where, K means 1024 bytes and M means 1024 ^ 2 = 1048576 bytes. The suffixes are not case sensitive. <SizeSymbol> A simple expression of the form <Symbol>[.member[...]] that denotes a symbol which contains a positive integer value as a size of the data in bytes to be erased. <Symbol>[.member[...]] A simple expression that results into either a global kernel symbol name or its member components. The expression always uses '.' operator to specify the member component of kernel symbol or its member irrespective of whether it is of pointer type or not. member[...] Member or component of member in <Symbol>. The erase command takes two arguments 1. kernel symbol name or its member components and 2. size of the data referred by argument (1) OR nullify keyword. The second argument size OR nullify is optional. The unit for size value is in bytes. If size option is not specified then the size of the first argument is determined according to its data type using dwarf info from debuginfo file. In case of 'char *' data type, the length of string pointed by 'char *' pointer is determined with an upper limit of 1024. The size can be specified in two forms 1. a integer value as explained above (<SizeValue>) and 2. a simple expression in the form of <Symbol>[.member[...]]] that results into base type (integer) variable. If the specified <Symbol> is of type 'void *', then user needs to provide either size or nullify option, otherwise the erase command will not have any effect. The nullify option only works if specified <Symbol> is a pointer. Instead of erasing data pointed by the specified pointer nullify erases the pointer value and set it to '0' (NULL). Please note that by nullifying the pointer values may affect the debug ability of created DUMP- FILE. Use the nullify option only when the size of data to be erased is not known. e.g. data pointed by 'void *'. Let us look at the makedumpfile.conf file from the example below which was configured to erase desired kernel data from the kernel module with name mymodule. At line 1 and 3, the user has not specified size option while erasing 'array_var' and 'mystruct1.name' symbols. Instead the user depends on makedumpfile to automatically determine the sizes to be erased i.e 100 bytes for 'array_var' and 11 bytes for 'mys- truct1.name'. At line 2, while erasing the 'mystruct1.buffer' member the user has specified the size value 25 against the actual size of 50. In this case the user specified size takes the precedence and makedumpfile erases only 25 bytes from 'mystruct1.buffer'. At line 4, the size of the data pointed by void * pointer 'mystruct1.addr' is unknown. Hence the nullify option has been specified to reset the pointer value to NULL. At line 5, the 'mystruct2.addr_size' is specified as size argument to determine the size of the data pointed by void * pointer 'mystruct2.addr'. Example: Assuming the following piece of code is from kernel module 'mymodule': struct s1 { char *name; void *addr1; void *addr2; char buffer[50]; }; struct s2 { void *addr; long addr_size; }; /* Global symbols */ char array_var[100]; struct s1 mystruct1; struct s2 *mystruct2; int foo() { ... s1.name = "Hello World"; ... } makedumpfile.conf: [mymodule] erase array_var erase mystruct1.buffer size 25 erase mystruct1.name erase mystruct1.addr1 nullify # Assuming addr2 points to 1024 bytes erase mystruct1.addr2 size 1K erase mystruct2.addr size mystruct2.addr_size EOF Loop construct A Loop construct allows the user to traverse the linked list or array elements and erase the data contents referred by each element. for <id> in {<ArrayVar> | <StructVar> via <NextMember> | <ListHeadVar> within <StructName>:<ListHeadMember>} erase <id>[.MemberExpression] [size <SizeExpression>|nullify] [erase <id>...] [...] endfor where <id> Arbitrary name used to temporarily point to elements of the list. This is also called iteration variable. <ArrayVar> A simple expression in the form of <Symbol>[.member[...]] that results into an array variable. <StructVar> A simple expression in the form of <Symbol>[.member[...]] that results into a variable that points to a structure. <NextMember> Member within <StructVar> that points to an object of same type that of <StructVar>. <ListHeadVar> A simple expression in the form of <Symbol>[.member[...]] that results into a variable of type struct list_head. <StructName> Name of the structure type that can be traversed using HEAD variable <ListHeadVar> and contains a member named <ListHeadMember>. <ListHeadMember> Name of a member in <StructName>, of type struct list_head. <MemberExpression> A simple expression in the form of [.member[...]] to specify a member or component of an element in <ArrayVar>, <StructVar> or <StructName>. <SizeExpression> Size value in the form of <SizeValue>, <id>[.MemberExpression] or <Symbol>[.member[...]]. The for loop construct allows to iterate on list of elements in an array or linked lists. Each element in the list is assigned to iteration variable <id>. The type of the iteration variable is determined by that of the list elements. The entry specified after 'in' terminal is called LIST entry. The LIST entry can be an array variable, structure variable/pointer or a struct list_head type variable. The set of erase commands specified between for and endfor, will be executed for each element in the LIST entry. If the LIST entry specified is an array variable, then the loop will be executed for each array element. The size of the array will be determined by using dwarf information. If the LIST entry specified is a structure variable/pointer, then a traversal member (<NextMember>) must be specified using 'via' terminal. The for loop will continue until the value of traversal member is NULL or matches with address of the first node <StructVar> if it is a circular linked list. If the LIST entry is specified using a struct list_head type variable, then within terminal must be used to specify the structure name <StructName> that is surrounding to it along with the struct list_head type member after ':' which is part of the linked list. In the erase statement <id> then denotes the structure that the list_head is contained in (ELEMENT_OF). The below example illustrates how to use loop construct for traversing Array, linked list via next member and list_head. Example: Assuming following piece of code is from kernel module 'mymodule': struct s1 { struct *next; struct list_head list; char private[100]; void *key; long key_size; }; /* Global symbols */ struct s1 mystruct1; static LIST_HEAD(s1_list_head); struct s1 myarray[100]; void foo() { struct s1 *s1_ptr; ... ... s1_ptr = malloc(...); ... ... list_add(&s1_ptr->list, &s1_list_head); ... } makedumpfile.conf: [mymodule] # erase private fields from list starting with mystruct1 connected via # 'next' member: for mys1 in mystruct1 via next erase mys1.private erase mys1.key size mys1.key_size endfor # erase private fields from list starting with list_head variable # s1_list_head. for mys1 in s1_list_head.next within s1:list erase mys1.private erase mys1.key size mys1.key_size endfor # erase private fields from all elements of the array myarray: for mys1 in myarray erase mys1.private erase mys1.key size mys1.key_size endfor EOF In the above example, the first for construct traverses the linked list through a specified structure variable mystruct1 of type struct s1. The linked list can be traversed using 'next' member of mystruct1. Hence a via terminal has been used to specify the traversal member name 'next'. The second for construct traverses the linked list through a specified struct list_head variable s1_list_head.next. The global symbol s1_list_head is a start address of the linked list and its next member points to the address of struct list_head type member 'list' from struct s1. Hence a within terminal is used to specify the structure name 's1' that can be traversed using s1_list_head.next variable along with the name of struct list_head type member 'list' which is part of the linked list that starts from s1_list_head global symbol. The third for construct traverses the array elements specified through a array variable myarray. SEE ALSO
makedumpfile(8) makedumpfile v1.4.3 29 February 2012 MAKEDUMPFILE.CONF(5)
All times are GMT -4. The time now is 08:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy