Sponsored Content
Top Forums Shell Programming and Scripting Joining two arrays and then creating a variable Post 302243417 by carlos25 on Sunday 5th of October 2008 11:29:11 AM
Old 10-05-2008
Basically what I want to do is take SURNAME and assign it to NAME as a variable for each element.
This is what I have come up with... ( adding/changing - [ typeset NAME[$i]="${SURNAME[$i]}" ])
Code:
#!/bin/bash

NAME="John" "Mary" "Fred"
SURNAME="Doe" "Poppins" "Flintstone"

for i in $@
do

NAME[${#NAME[@]}]=$i
SURNAME[${#SURNAME[@]}]=$i
done

for ((i=0; i < ${#NAME[@]}; i++))
do

typeset NAME[$i]="${SURNAME[$i]}"

done

echo "$John"
echo "$Mary"
echo "$Fred"

As I mentioned in my original post I got it to work another way and couldn't replicate it again. I was just wondering if it was a fluke or another way of assigning an array I was not aware of.

A follow-up question to this is how I would approach combining the two arrays together into another single array?

example: display_name="NAME[$i] ${SURNAME[$i]}"

So that it would echo ${display_name[0]} and return "John Doe"

---
Carl
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell: creating different arrays based on function argument

hi, I was wondering if there was a good way to create an array within a function, where the name is based on a passed argument? I tried this: _____________________________ func(){ #take in 1st arg as the arrayname arrayName=$1 let i=0 while read line do arrayName=${line} let i+=1... (5 Replies)
Discussion started by: nix21
5 Replies

2. Shell Programming and Scripting

Creating an unknown number of arrays

I need to create arrays like this: cnt=0 { while read myline; do if ];then firstpass="${myline##<meas>}" meas="${firstpass%%</meas>}" tempmeas="${meas%%;*}" MEAS$cnt=$tempmeas print $cnt print ${MEAS'$cnt'} ... (2 Replies)
Discussion started by: ajgwin
2 Replies

3. UNIX for Dummies Questions & Answers

joining variable to the end of a file name

hi all i have a directory which contain file 20060101-66666-09-08-0.tif 20060101-77777-11-12-0.tif 20051231-54221-66-55.tif 20051231-54221-66-44.tif as you can see the name of the two last files is shorter then the first ones i want to take all the files with the shorter name and to add to... (7 Replies)
Discussion started by: naamas03
7 Replies

4. Shell Programming and Scripting

variable joining

I really need help on this problem. The story: My VAR1 and VAR2 works fine and able to get the value. I want to do as "if VAR1 or VAR2 is bigger than max_loadavg then the code will run...then if VAR1 or VAR2 is lesser than min_loadavg then the other code will run... The problem: The... (8 Replies)
Discussion started by: hezry79
8 Replies

5. Shell Programming and Scripting

Need help in creating arrays using shell

Hi, I need help in creating a array in shell scirpt. I have a file which has following details. hostname devices device1 device 2 de abcdmhs10 1234 2343 2353 3343 3435 2343 bcdfmhs11 2343 2443 3434 8874 0343 3434 (5 Replies)
Discussion started by: jpkumar10
5 Replies

6. Shell Programming and Scripting

awk arrays - compare value in second column to variable

Hello, I am trying to redirect files to a directory by using a config file. The config files is as such: xxxxxx,ID,PathToDirectory xxxxxx,ID2,PathToDirectory2 and so on... I have a variable that should match one of these IDs. I want to load this config file into an awk array, and... (2 Replies)
Discussion started by: jrfiol
2 Replies

7. Shell Programming and Scripting

Bash for loop with arrays second variable?

I am fairly new to bash and am not sure how to resolve this: I have a series of geographical long/lat points eg. 50/-30 listed on separate lines in a file called junk2. I have input these into an array and am then using that array in a for loop. Towards the end of the loop I create a file called... (4 Replies)
Discussion started by: lily-anne
4 Replies

8. Shell Programming and Scripting

Multiple arrays in variable using for loop

Hi, I'm trying to get the number of files inside same kind of folders on each disks and assigning each values in to a variable named with same folder and disk name so that it'll be easy for me to identify each time.But somehow I'm not able to assign those values in that specific name variable... (1 Reply)
Discussion started by: ratheeshp
1 Replies

9. Shell Programming and Scripting

Variable substitution with arrays

Hi all, I have a script with the following gist: declare -a index=(0 1 2 3 4); declare -a animals=(dog cat horse penguin cow); declare -a fruits=(orange apple grapes peach mango); declare -a drinks=(juice milk coffee tea coke); declare -a cities=(toronto paris london glasgow... (18 Replies)
Discussion started by: Kingzy
18 Replies

10. Shell Programming and Scripting

Creating script with multiple job arrays

Hello everyone, First of all this is my first post and im fairly new to working with Unix and creating scripts etc. so there will probably be wrong phrases used. Lets get to my questions. I have multiple scripts that submit Slurms/Jobs to the cluster starting like this and doing certain... (3 Replies)
Discussion started by: idbemad
3 Replies
Biber::Input::file::zoterordfxml(3pm)			User Contributed Perl Documentation		     Biber::Input::file::zoterordfxml(3pm)

   extract_entries
	  Main data extraction routine.
	  Accepts a data source identifier (filename in this case),
	  preprocesses the file and then looks for the passed keys,
	  creating entries when it finds them and passes out an
	  array of keys it didn't find.

   create_entry
	  Create a Biber::Entry object from an entry found in a Zotero
	  RDF/XML data source

   parsename
	   Given a name node, this function returns a Biber::Entry::Name object

	   Returns an object which internally looks a bit like this:

	   { firstname	   => 'John',
	     firstname_i   => 'J',
	     middlename    => 'Fred',
	     middlename_i  => 'F',
	     lastname	   => 'Doe',
	     lastname_i    => 'D',
	     prefix	   => undef,
	     prefix_i	   => undef,
	     suffix	   => undef,
	     suffix_i	   => undef,
	     namestring    => 'Doe, John Fred',
	     nameinitstring => 'Doe_JF',

NAME
Biber::Input::file::zoterordfxml - look in a Zotero RDF/XML file for an entry and create it if found DESCRIPTION
Provides the extract_entries() method to get entries from a Zotero RDF/XML data source and instantiate Biber::Entry objects for what it finds AUTHOR
Francois Charette, "<firmicus at ankabut.net>" Philip Kime "<philip at kime.org.uk>" BUGS
Please report any bugs or feature requests on our sourceforge tracker at <https://sourceforge.net/tracker2/?func=browse&group_id=228270>. COPYRIGHT &; LICENSE Copyright 2009-2012 Francois Charette and Philip Kime, all rights reserved. This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. perl v5.14.2 2012-06-17 Biber::Input::file::zoterordfxml(3pm)
All times are GMT -4. The time now is 10:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy