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
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
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
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
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
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
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
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
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
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
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
LEARN ABOUT PHP
array_diff_uassoc
ARRAY_DIFF_UASSOC(3) 1 ARRAY_DIFF_UASSOC(3)
array_diff_uassoc - Computes the difference of arrays with additional index check which is performed by a user supplied callback function
SYNOPSIS
array array_diff_uassoc (array $array1, array $array2, [array $...], callable $key_compare_func)
DESCRIPTION
Compares $array1 against $array2 and returns the difference. Unlike array_diff(3) the array keys are used in the comparison.
Unlike array_diff_assoc(3) an user supplied callback function is used for the indices comparison, not internal function.
PARAMETERS
o $array1
- The array to compare from
o $array2
- An array to compare against
o $...
- More arrays to compare against
o $key_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)
RETURN VALUES
Returns an array containing all the entries from $array1 that are not present in any of the other arrays.
EXAMPLES
Example #1
array_diff_uassoc(3) example
The "a" => "green" pair is present in both arrays and thus it is not in the output from the function. Unlike this, the pair 0 =>
"red" is in the output because in the second argument "red" has key which is 1.
<?php
function key_compare_func($a, $b)
{
if ($a === $b) {
return 0;
}
return ($a > $b)? 1:-1;
}
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
$result = array_diff_uassoc($array1, $array2, "key_compare_func");
print_r($result);
?>
The above example will output:
Array
(
[b] => brown
[c] => blue
[0] => red
)
The equality of 2 indices is checked by the user supplied callback function.
NOTES
Note
This function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example,
array_diff_uassoc($array1[0], $array2[0], "key_compare_func");.
SEE ALSO
array_diff(3), array_diff_assoc(3), array_udiff(3), array_udiff_assoc(3), array_udiff_uassoc(3), array_intersect(3), array_inter-
sect_assoc(3), array_uintersect(3), array_uintersect_assoc(3), array_uintersect_uassoc(3).
PHP Documentation Group ARRAY_DIFF_UASSOC(3)