Sponsored Content
Top Forums Shell Programming and Scripting Parameter Problem With an Array Variable Post 302232371 by msb65 on Thursday 4th of September 2008 10:27:22 AM
Old 09-04-2008
Parameter Problem With an Array Variable

Hi,

I have two bash shell scripts:

test:

rrdhcp78-120:test_data msb65$ cat ~/bin/test
#!/bin/sh

array1=()
echo 'elements in array1:' ${#array1[@]}

~/bin/test2 $array1

test2:

rrdhcp78-120:test_data msb65$ cat ~/bin/test2
#!/bin/sh

array2=${1}
echo 'elements in array2:' ${#array2[@]}

When I run test:

rrdhcp78-120:test_data msb65$ ~/bin/test
elements in array1: 0
elements in array2: 1

Why is it that "array1" initially has 0 elements, but when I export the variable to test2, assign it to variable "array2", it then has 1 element?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Array as parameter

Can I pass and array as a function paramter? #!/bin/bash a1=one a1=two a2=one a2=two function f1() { array1copy=( ${1} ) array2copy=( ${2} ) echo "${array1copy}" echo "${array2copy}" } f1 "${a1}" "${a2}" (2 Replies)
Discussion started by: newbreed1
2 Replies

2. Shell Programming and Scripting

How to check parameter variable?

Hello All, I have a script that will email out if the email address is specified as parameter 1. I am using ksh, and then tried the following : email=$1 Following did not work, I am getting error test -z $email test ${email:=" ") -eq " " test -n $email test ${?email} What... (4 Replies)
Discussion started by: negixx
4 Replies

3. Shell Programming and Scripting

Assign value to a variable in a parameter file

Hi, I have a parameter file and it contains following items $ cat TransactionParams From_Date_Parm=2005-02-25 To_Date_Parm=2005-05-25 Extract_Root_Parm=/detld1/etl/ascential/Ascential/DataStage/Projects/CTI_London/IAM Extract_Type_Parm=Transaction EDW_Database_Parm=hdw_erks... (2 Replies)
Discussion started by: gopskrish
2 Replies

4. Shell Programming and Scripting

Array as a Parameter

In a ksh shell... I need to pass 12 parameters to a secondary ksh shell. In VB I would just pass an array that contains all of these, but haven't been successful in passing the full array in a KSH shell. Does anyone have an example where you can pass an array as a parameter? here's what i... (3 Replies)
Discussion started by: heyindy06
3 Replies

5. Shell Programming and Scripting

Reading a variable from parameter file

HI all, I have a parameter file with entries like $$Name =Abhinav $$CUTOFF_DATE = 11/11/2209 I am reading a variable from this file using a awk command like : var2=`awk -F"" "/CUTOFF_DATE/{f=$1;}{print f;}" InputFIleName` but facing an error like awk: cmd. line:1:... (3 Replies)
Discussion started by: abhinav192
3 Replies

6. Shell Programming and Scripting

How to pass a function with a variable parameter into another variable?

Hello again :) Am currently trying to write a function which will delete a record from a file. The code currently looks as such: function deleteRecord() { clear read -p "Please enter the ID of the record you wish to remove: " strID ... (2 Replies)
Discussion started by: U_C_Dispatj
2 Replies

7. Shell Programming and Scripting

using an awk internal variable as parameter for an external array

Hello, I am running a bash script under linux which first defines an CA-array like j=0 num1=120.00 num2=10.00 until do CA='echo $num1 + $j*$num2' j=$ done within the later awk section of this same script I want to read data from a file. If the value of the second column is... (3 Replies)
Discussion started by: MotAah
3 Replies

8. Shell Programming and Scripting

Attempting to pass my array as a nested parameter to loop. A little lost.

I want to pass this array as a parameter. IFS=$'\n' fortune_lines=($(fortune | fold -w 30 )) Inside of this line screen -p 0 -S ${SCREEN_SESSION} -X stuff "`printf "say ${fortune_lines}\r"`" And I am lost at this point. I am thinking something like this? Then make it loop.. ... (7 Replies)
Discussion started by: briandanielz
7 Replies

9. Shell Programming and Scripting

Problem with awk array when loading from shell variable

Hi, I have a problem with awk array when iam trying to use awk in solaris box as below..Iam unable to figure out the problem.. Need your help. is there any alternative to make it in arrays from variable values nawk 'BEGIN {SUBSEP=" "; split("101880|110045 101887|110045 101896|110045... (9 Replies)
Discussion started by: cskumar
9 Replies

10. Shell Programming and Scripting

Identify the Parameter variable file

Hi I am trying to understand a shell scipt file ( .ksh file ) . In the shell script we are referring a variable . Example : SessLogs=$STAFF_MSTR_DIR/staff_dtls There are no references in the shell script from where the variable "$STAFF_MSTR_DIR" is being read from . Could anyone... (2 Replies)
Discussion started by: Sudheer Maddula
2 Replies
ARRAY_UINTERSECT_UASSOC(3)						 1						ARRAY_UINTERSECT_UASSOC(3)

array_uintersect_uassoc  -  Computes  the intersection of arrays with additional index check, compares data and indexes by separate callback func-
tions

SYNOPSIS
array array_uintersect_uassoc (array $array1, array $array2, [array $...], callable $value_compare_func, callable $key_compare_func) DESCRIPTION
Computes the intersection of arrays with additional index check, compares data and indexes by separate callback functions. PARAMETERS
o $array1 - The first array. o $array2 - The second array. o $value_compare_func - The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. int callback (mixed $a, mixed $b) o $key_compare_func - Key comparison callback function. RETURN VALUES
Returns an array containing all the values of $array1 that are present in all the arguments. EXAMPLES
Example #1 array_uintersect_uassoc(3) example <?php $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "GREEN", "B" => "brown", "yellow", "red"); print_r(array_uintersect_uassoc($array1, $array2, "strcasecmp", "strcasecmp")); ?> The above example will output: Array ( [a] => green [b] => brown ) SEE ALSO
array_uintersect(3), array_intersect_assoc(3), array_intersect_uassoc(3), array_uintersect_assoc(3). PHP Documentation Group ARRAY_UINTERSECT_UASSOC(3)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy