Programming :: Initializing Arrays In The Bash?

Mar 12, 2009

I'm making script for automated compiling of one program which would output builds optimized for many architectures. For clearancy, I do each build in it's own catalogue and list of builds with their respective catalogues would be stored as array. I'm using this guide as reference. It describes making array as naming a variable with additional brackets denoting it's position in array.

In my code, it looks exactly like this:

Code:

mtune[1]="build/mtune/athlon"
mtune[2]="build/mtune/athlon-4"
mtune[3]="build/mtune/athlon-mp"

[code]....

But upon invoking $mtune or any $mtune[x] variable, output is blank, like the variable(s) were never initialized. What am I doing wrong?

View 1 Replies


ADVERTISEMENT

Programming :: Bash: Combine Arrays & Delete Duplicates?

May 23, 2011

I would like to combine two arrays and delete duplicates that might occur. I tried to solve it like this:

Code:
combined=( "${results1[@]}" "${results2[@]}" )
printf "${combined[@]}" | sort -n | uniq
Example:
result1 (4 elements):

[Code]....

In my code printf seems to have a problem with elements that have the same letters but a space inbetween. For instance "new foo", "newfoo" are the same for printf

View 5 Replies View Related

Programming :: Bash Scripting Arrays And Indirect Referencing

Feb 23, 2010

I've got a situation. I'm having GNU bash version 3.00.16(1) on Solaris 10. I need to declare an array say arr1 which will be populated by an output of a command.

declare -a arr1
arr1=( $(/some/command) )

Supposing it will eventually (after executing the command) have element values as -

arr1[0]=1234
arr1[1]=5678
arr1[2]=7890

Now, I need to declare another set of arrays, one for each of the element values above - e.g.

declare -a arr1_1234
declare -a arr1_5678
declare -a arr1_7890

And I also need to populate elements of each of above 3 arrays with output of another command in a loop. So, these arrays will hold values something like -

arr1_1234[0]="abc"
arr1_1234[1]="def"
arr1_1234[2]="ghi"

arr1_5678[0]="jkl"
arr1_5678[1]="mno"
arr1_5678[2]="pqr"
arr1_7890[0]="tuv"
arr1_7890[1]="xyz"
arr1_7890[2]="aab"

I'm able to declare and populate arr1[*]. My question is how do I declare, populate and print the subsequent arrays and their elements?I am feeling rather thick to get this working.

View 7 Replies View Related

General :: Comparing Arrays In Bash ?

Jun 2, 2010

Is there a way to compare an array in a while conditions?

I have one array that contains the results of some search and if the script has found all the items, then it should stop, so my idea is to have a while loop � la:


Code:

View 4 Replies View Related

General :: Compare Two Arrays In Bash?

Sep 30, 2010

I am writing a script to get the multiples of 2 and 3, place them in an 2 arrays, and then show the common integers. So far everything works fine till the comparision. I don't know how to compare them. Here is the code:

Code:

#!/bin/bash
let num1="2"
let num2="3"

[code]...

View 6 Replies View Related

Software :: Bash Arrays And Quotes (PvPGN)

Aug 23, 2010

I am trying to get PvPGN working... I have installed all the files, the only thing now is that bntrackd wants to use 'logs/bntrackd.log' for it's logfile, but seeing as it's in /usr/sbin, I want it to use /var/log/bntrackd. This is done with 'bntrackd --logfile=/var/log/bntrackd.log' but when I put that in the script it won't process it as a command (instead splitting it and complaining that I don't have --logfile=/var/log/bntrackd.log installed)

/etc/rc.d/pvpgn:

Code:
#!/bin/bash
...
[ -z "$PVPGN_DAEMONS" ] && PVPGN_DAEMONS=(bnetd d2dbs d2cs)
...
for d in ${PVPGN_DAEMONS[@]}; do

[Code]....

View 4 Replies View Related

Programming :: Arrays In The C Programming Language Are Pointers To The First Element Of The Array?

Mar 27, 2010

I wonder why arrays in the C programming language are pointers to the first element of the array, not the first element of the array itself?

View 14 Replies View Related

Programming :: Initializing A Structure To Zero?

Nov 20, 2009

I have a struct (small instance so not using code brackets )

struct random {
int a;
int b;
}example;

What i am trying is

example={0,0};

and it gives an error how to initialize all the entries within a struct to zero? In the above example i have used integers but what if they are some other data structure for example another structure?

View 2 Replies View Related

Programming :: Initializing A Variable In C?

Nov 5, 2010

Following is the way I saw a variable initialized in C

Code:

static const unsigned int rtl8139_rx_config =
RxCfgRcv64K |
(RX_FIFO_THRESH << RxCfgFIFOShift) |
(RX_DMA_BURST << RxCfgDMAShift);

on following link

[URL]

I have initialized variables in past but above initialization I could not understand what is it?

View 4 Replies View Related

Programming :: Semaphore Used Without The Initializing?

Nov 4, 2010

I am using semaphore.h I declared a variable of type sem_t. I am able to use the variable without even calling sem_init or sem_open, and it is working properly.if the variable is automatically assigned some value? Also would I run into any trouble doing so?

View 1 Replies View Related

Programming :: Initializing Pmw Megawidgets For Python 2.6

Oct 12, 2010

I am having a problem initializing the Pmw megawidgets for Python 2.6.I have Pmw_1_3 loaded in the site-packages directory.

View 1 Replies View Related

Programming :: Error While Executing Scripts And Initializing Exe's?

Oct 13, 2010

I am having the following error while executing script and initialing my application

./ss.sh: line 1: kk.sh: command not found
./ss.sh: line 2: mon.exe: command not found

Can somebody assist ASAP.

View 4 Replies View Related

Programming :: C++ - Initializing Static Member Array?

Jun 7, 2011

The code below defines an array of structures in a class. I would like this to be a Static array and then initialize the array in a initialization method. I understand that initialization lists are the way to go but due to the size and complexity of the array I plan on using (the example below is a simple snippet that illustrates the problem) I would like to use the initialization method. However, I cant even get this thing to compile. The error says the reference to the ArrayOfStructs in the initialization routine is undefined.

l_long_Island

P.S. This is the error message

undefined reference to `ClassWithStaticArray::ArrayOfStruts'

class ClassWithStaticArray {
public:
struct IntegerStruct
{

[code]....

View 5 Replies View Related

Programming :: Declaration A Variable In One File And Initializing In Another?

Nov 25, 2010

I made 2 files which are different from the program above one is temp1.h and another is temp2.c to understand how extern is used. So here is temp1.h

Code:

#include<stdlib.h>
typedef struct node * bond;
extern int jk;

and temp2.c is

Code:

#include<stdio.h>
#include<temp1.h>
struct node {
int data;

[code]...

I had declared jk in temp1.h as an extern int so why can I not initialize it in temp2.c?

View 5 Replies View Related

Programming :: Initializing The SS Register (Intel Architecture)?

Jul 9, 2011

Kernel 2.6.21.5, slackware 12.0 as 2.17 [I am speaking here about 80x86 processors, with their segment registers SS, DS, CS, ES.] In a source file for as, I wrote

Code:

.section _STACK
.rept 4096
.word 0
.endr

Now, in the .text section, I want to initialize SS, the stack segment, to point to the _STACK section. In other assemblers, there was a special section for the stack, and the linker cared about initializing SS. Here I use a common section for the stack. For a segment such as DS, I could write

mov ax,_DATA
mov ds,ax

But I don't think mov ax,_STACK would do with as/ls.how do I initialize SS?

View 4 Replies View Related

Programming :: Adding Two Arrays?

Mar 1, 2010

I have a problem on a program,the problem take a very long time when i try to add two big arrays element by elementI know that matlab make adding vectors more faster than adding element by element but I don't know how!!!do any body knew how matlab make vectors operations more faster than element by element???I want to make my calculation more faster because the program is very big

View 8 Replies View Related

Programming :: Character Arrays In C?

Nov 3, 2010

I was reading Kernighan Ritchie book chapter 4 which deals with character pointers.I am not able to understand following different type of declarations

Code:
char aname[][15] = { "Illegal month", "Jan", "Feb", "Mar" };
char amessage[] = "now is the time";

[code]...

View 1 Replies View Related

Programming :: Using Of Arrays In Loops?

Sep 3, 2009

need to process files within multiple directories and transfer these to a remote server. What I had in mind was to use arrays for this; code pasted below (explains it better):

Code:
#set the arrays
array_A=( fileA* pathtodestA hostA passwordA )

[code]...

View 8 Replies View Related

Programming :: Can Diff Take Arrays As Input

Jun 19, 2010

Does diff not like arrays? How do achieve the following?

Code:

stuart@stuart:~/music transfer$ diff file1.txt file2.txt
1c1
< bonkers_in_phoenix.mp3

[code]....

View 14 Replies View Related

Programming :: Printing 2 Arrays To 2 Columns?

Jun 16, 2010

I have a Perl script that has two arrays - they are related. I would like to print out the contents into two columns next to each other.

#!/usr/bin/perl
open(PINGFILE, </home/casper/pingdata.txt") or die " can not open file ";
my @totalfile=<PINGFILE>;
foreach $string(@totalfile) {
if ($string =~ m/(^1sping)(?=.*max))/) {
push(usecstring,"$string");

[Code]...

View 2 Replies View Related

Programming :: Structures And String Arrays, C?

Apr 18, 2011

I am working on a project that needs to use structures and I'm pretty sure string arrays. First I declare my structures and they must be exactly like this.

typedef struct
{
int hour;

[code]....

View 4 Replies View Related

Programming :: Initializing My Application - Error While Loading Shared Libraries ?

Oct 14, 2010

While initializing my application the following errors is returned:

Bash profile for the user is as follows:

View 1 Replies View Related

Programming :: Initializing A Branch In One Launchpad Project On Multiple Computers?

Mar 25, 2010

initializing a branch in one Launchpad project on multiple computers, or even upon reinstalling an OS? I know I sure haven't.

View 1 Replies View Related

Programming :: Create A Small Array Of 3x3 Arrays?

Jul 12, 2009

I'm trying to figure how to create an small array of 3x3 arrays such I can do

Code:

SUM1(i) = SUM1(i) + SUM2

where i goes from 1 to 8 and SUM2 is a 3x3 array.

View 2 Replies View Related

Programming :: Read Text File Using Arrays In C++?

Oct 19, 2010

a project using bluetooth to send data byte by byte to external devices buti'm not familiar using arrays to read file from another location before sending the data.If you could,do correct my codes.Here's my code,

void loop(){
char Msg[]={"Hello"};
char *start;

[code]...

View 2 Replies View Related

Programming :: Get Number Of Elements In A Hash Of Arrays?

Dec 10, 2008

I have something like this:

$arr_hash{'produce'}{'veggies'}[0] = Broccoli
$arr_hash{'produce'}{'veggies'}[1] = Cauliflower
$arr_hash{'produce'}{'veggies'}[2] = Carrots

[code]...

View 2 Replies View Related

Programming :: Perl - Pointers To Arrays From Hashes?

Feb 18, 2010

I'm trying to figure out how to code for this specific type of instance - I want to use a hash and have the key be a reference to an array, and not use the key in the standard way of it being a scalar. Basically, I have a large output that I need to process line by line, and rather have access to it as an array than a big block in a scalar. For the big block hash as a scalar I would do -

Code:
foreach $CONTROLLER (<CONTROLLER_LIST>) {
$ALL_DISKS{$CONTROLLER} = `ssh -n <commands>`;
}

Now I know I could take the scalar and split it to another array after the fact like -

Code:
@TEMP_HOLD = split (/s+/,$ALL_DISKS{$CONTROLLER});

How would I code it that I would have access to the key information as an array and not a scalar? I know it needs to be a pointer and we're going to have -> in there somewhere, but not sure how to approach it. Some of the documentaiton I've been reading about referencing I've found a little confusing so far, and trying to figure out how to use them in context of what I'm working on.

View 1 Replies View Related

Programming :: If Test Validation - Using Char Arrays

Jun 9, 2010

I'm writing a code to get the index of the last occurrence of a given substring in a string.

Code:
int StringHandler::lastIndexOf(string src, const string s) {
unsigned int lastIndex = string::npos;
if (src.find(s, 0) == string::npos) {
return -1; } else {
bool isLast = false; unsigned int i = 0; do {
lastIndex = src.find(s, i);
if (lastIndex != string::npos) { i = lastIndex + 1;
if (i == src.size()) { isLast = true;
} } else { isLast = true;
} } while (!isLast);
} return lastIndex;
}

My problem is: execution steps into an if with a false condition! Check the values of i and src.size() at the right panel. How could be possible for the program to run the highlighted statement? The if condition above is false! [URL]. I could use char arrays, for example, but this kind of false validation has happened to me more than once, I'm using G++ 4.5 with these flags: -O0 -g -Wall -c

View 3 Replies View Related

Programming :: PHP - Sorting Multi Dimensional Arrays By One Column

Mar 17, 2009

I just started programming in PHP so I haven't figured out how to do this yet, but I have a multi-dimensional array that I need to sort by one column. That's fine...but I need the sort to ignore case! Right now I have it sorted by 'name' (the other column is 'uid').

The problem is that by the default the sort is case-sensitive so the array looks like this:
Code:
Apple 4015
Banana 4011
Cherry 4045
avocado 4046

I want to be able to sort the the 'name' column in a case-insensitive manner so that the array actually looks like:
Code:
Apple 4015
avocado 4046
Banana 4011
Cherry 4045

How to accomplish this? Just FYI I'm not actually sorting the PLUs for fruits...but it was a simple example. I'm actually doing this for a Facebook application.

View 2 Replies View Related

Programming :: Multi Dimensional Arrays In C Of Variable Size

Apr 15, 2010

I am curious if there is a way to describe and use variable sized multi-dimensional arrays in C using pointers. I mean, for 1-dimensional array e.g. I can use the following piece of code:

...
int i , N;
int *array;
scanf("%d", &N);
array = (int*) malloc(N*sizeof(int));
for (i=0; i<N; ++i) array[i] = i; // Assigning values to the array
for (i=0; i<N; ++i) printf("%d ", array[i]); // Printing the assigned values
free (array);
...

But what about the two dimensional array[N][M] ? I guess I have to use a double pointer e.g: int **array. But how exactly? Note that I use C90 and not C99.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved