Sponsored Content
Top Forums Shell Programming and Scripting Global declaration of Array in Shell Post 302857639 by periyasamycse on Thursday 26th of September 2013 08:20:35 PM
Old 09-26-2013
Global declaration of Array in Shell

Hi,

Have assigned values in Array and iterating in while loop and would require values outside of the loop. But its returning NULL.

could you please help us how to define Global array declaration in Unix shell scripting?

i am using Kron shell.

Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Array Declaration and For Loop

I am just stucked in syntax.This is more like a array and for loop problem. I want to use ls -l command and get filezise and filename of all filenames in the directory in an array (say array#1). After 2 minutes of sleep, i want to get the same information in another array (say array#2). The... (4 Replies)
Discussion started by: 33junaid
4 Replies

2. Shell Programming and Scripting

Global variable declaration in shell scripting

Hi all, How to print variable value which i have assigned inside for loop because that variable scope is local, but i want to use that variable outside for loop. Awaiting your great help Thanks, Susil (1 Reply)
Discussion started by: susilgandhi
1 Replies

3. Solaris

i cannot give array declaration in shell script

Dear all, i m unable to give array decalartion in solaris Operating system shell script and script was so.sh declare -a bull for i in 1 2 3 4 5 6 7 8 9 do bull=$i echo "${bull}" done it is throwing an error called so.sh: declare: not found so.sh: bull=1: not... (20 Replies)
Discussion started by: naree
20 Replies

4. Shell Programming and Scripting

global date for many scripts in shell

Hi, I am using shell (#!/bin/bash), i am trying to set my date in a script date.sh, i want this dates to be used by another scripts. I have tried to make: #!/bin/bash begin_date =`date +%Y_%m_%d_%H_%M_%S`, i also tried: #!/bin/bash begin_date =20080709 12:14:11, then i write in... (11 Replies)
Discussion started by: rosalinda
11 Replies

5. UNIX for Dummies Questions & Answers

Array declaration problem

Hi all, I would like to declare a vector of variables and access them sequentially. Here is my code ARRAY_CT="0001000000 0000100000 0000010000" ELEMENTS_CT=${#ARRAY_CT} echo $ELEMENTS_CT for (( j=1;j<=$ELEMENTS_IS;j++)); do echo ${ARRAY_IS} done ... (2 Replies)
Discussion started by: f_o_555
2 Replies

6. Solaris

How to access ENV variables of non global zones in global zone???

Hi Guys, My requirement is I have file called /opt/orahome/.profile in non global zone. PATH=/usr/bin:/usr/ucb:/etc:/usr/sbin:/usr/local/bin:/usr/openwin/bin:. export PATH PS1="\${ORACLE_SID}:`hostname`:\$PWD$ " export PS1 EDITOR=vi export EDITOR ENV=/opt/orahome/.kshrc export ENV... (1 Reply)
Discussion started by: vijaysachin
1 Replies

7. Shell Programming and Scripting

Array declaration in Shell script

this is my code declare -a USERCERT declare -a CACERT declare -a KEYSRC this is the error + declare -a USERCERT ./clone.sh: 1: declare: not found + declare -a CACERT ./clone.sh: 1: declare: not found + declare -a KEYSRC ./clone.sh: 1: declare: not found (11 Replies)
Discussion started by: xerox
11 Replies

8. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies

9. Solaris

Global and non-global zone resource sharing - tricky

hi all, Just a simple question but i cant get the answers in the book - In my globalzone , assuming i have 4 cpus (psrinfo -pv = 0-3), if i set dedicated-cpu (ncpus=2) for my local zone Is my globalzone left with 2 cpus or still 4 cpus ? Does localzone "resource reservation.e.g. cpu in... (6 Replies)
Discussion started by: javanoob
6 Replies

10. Shell Programming and Scripting

Array - Export/Import in global environment variables.

Hello. During startup /etc/bash.bashrc.local generates some array ..... source /.../.../system_common_general_array_env_var ..... The file system_common_general_array_env_var contains : LEAP_VERSION='42.3' ARRAY_MAIN_REPO_LEAP=('zypper_local' 'openSUSE-Leap-'"$LEAP_VERSION"'-Non-Oss' ... (2 Replies)
Discussion started by: jcdole
2 Replies
MakeMethods::Standard::Global(3pm)			User Contributed Perl Documentation			MakeMethods::Standard::Global(3pm)

NAME
Class::MakeMethods::Standard::Global - Global data SYNOPSIS
package MyClass; use Class::MakeMethods::Standard::Global ( scalar => [ 'foo' ], array => [ 'my_list' ], hash => [ 'my_index' ], ); ... MyClass->foo( 'Foozle' ); print MyClass->foo(); print MyClass->new(...)->foo(); # same value for any instance print MySubclass->foo(); # ... and for any subclass MyClass->my_list(0 => 'Foozle', 1 => 'Bang!'); print MyClass->my_list(1); MyClass->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle'); print MyClass->my_index('foo'); DESCRIPTION
The Standard::Global suclass of MakeMethods provides basic accessors for shared data. Calling Conventions When you "use" this package, the method names you provide as arguments cause subroutines to be generated and installed in your module. See "Calling Conventions" in Class::MakeMethods::Standard for more information. Declaration Syntax To declare methods, pass in pairs of a method-type name followed by one or more method names. Valid method-type names for this package are listed in "METHOD GENERATOR TYPES". See "Declaration Syntax" in Class::MakeMethods::Standard and "Parameter Syntax" in Class::MakeMethods::Standard for more information. METHOD GENERATOR TYPES
scalar - Global Accessor For each method name passed, uses a closure to generate a subroutine with the following characteristics: o May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on. o If called without any arguments returns the current value. o If called with an argument, stores that as the value, and returns it, Sample declaration and usage: package MyClass; use Class::MakeMethods::Standard::Global ( scalar => 'foo', ); ... # Store value MyClass->foo('Foozle'); # Retrieve value print MyClass->foo; array - Global Ref Accessor For each method name passed, uses a closure to generate a subroutine with the following characteristics: o May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on. o The global value will be a reference to an array (or undef). o If called without any arguments, returns the current array-ref value (or undef). o If called with a single non-ref argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef). o If called with a single array ref argument, uses that list to return a slice of the referenced array. o If called with a list of argument pairs, each with a non-ref index and an associated value, stores the value at the given index in the referenced array. If the global value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value. o If called with a list of argument pairs, each with the first item being a reference to an array of up to two numbers, loops over each pair and uses those numbers to splice the value array. The first controlling number is the position at which the splice will begin. Zero will start before the first item in the list. Negative numbers count backwards from the end of the array. The second number is the number of items to be removed from the list. If it is omitted, or undefined, or zero, no items are removed. If it is a positive integer, that many items will be returned. If both numbers are omitted, or are both undefined, they default to containing the entire value array. If the second argument is undef, no values will be inserted; if it is a non-reference value, that one value will be inserted; if it is an array-ref, its values will be copied. The method returns the items that removed from the array, if any. Sample declaration and usage: package MyClass; use Class::MakeMethods::Standard::Global ( array => 'bar', ); ... # Clear and set contents of list print MyClass->bar([ 'Spume', 'Frost' ] ); # Set values by position MyClass->bar(0 => 'Foozle', 1 => 'Bang!'); # Positions may be overwritten, and in any order MyClass->bar(2 => 'And Mash', 1 => 'Blah!'); # Retrieve value by position print MyClass->bar(1); # Direct access to referenced array print scalar @{ MyClass->bar() }; There are also calling conventions for slice and splice operations: # Retrieve slice of values by position print join(', ', MyClass->bar( undef, [0, 2] ) ); # Insert an item at position in the array MyClass->bar([3], 'Potatoes' ); # Remove 1 item from position 3 in the array MyClass->bar([3, 1], undef ); # Set a new value at position 2, and return the old value print MyClass->bar([2, 1], 'Froth' ); hash - Global Ref Accessor For each method name passed, uses a closure to generate a subroutine with the following characteristics: o May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on. o The global value will be a reference to a hash (or undef). o If called without any arguments, returns the contents of the hash in list context, or a hash reference in scalar context (or undef). o If called with one non-ref argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef). o If called with one array-ref argument, uses the contents of that array to retrieve a slice of the referenced hash. o If called with one hash-ref argument, sets the contents of the referenced hash to match that provided. o If called with a list of key-value pairs, stores the value under the given key in the referenced hash. If the global value was previously undefined, a new hash is autovivified. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the contents of the hash in list context, or a hash reference in scalar context. Sample declaration and usage: package MyClass; use Class::MakeMethods::Standard::Global ( hash => 'baz', ); ... # Set values by key MyClass->baz('foo' => 'Foozle', 'bar' => 'Bang!'); # Values may be overwritten, and in any order MyClass->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle'); # Retrieve value by key print MyClass->baz('foo'); # Retrive slice of values by position print join(', ', MyClass->baz( ['foo', 'bar'] ) ); # Direct access to referenced hash print keys %{ MyClass->baz() }; # Reset the hash contents to empty @{ MyClass->baz() } = (); object - Global Ref Accessor For each method name passed, uses a closure to generate a subroutine with the following characteristics: o May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on. o The global value will be a reference to an object (or undef). o If called without any arguments returns the current value. o If called with an argument, stores that as the value, and returns it, Sample declaration and usage: package MyClass; use Class::MakeMethods::Standard::Global ( object => 'foo', ); ... # Store value MyClass->foo( Foozle->new() ); # Retrieve value print MyClass->foo; SEE ALSO
See Class::MakeMethods for general information about this distribution. See Class::MakeMethods::Standard for more about this family of subclasses. perl v5.10.1 2004-09-06 MakeMethods::Standard::Global(3pm)
All times are GMT -4. The time now is 03:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy