Global declaration of Array in Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Global declaration of Array in Shell
# 1  
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.
# 2  
Old 09-26-2013
You say that this doesnt work?

Code:
ARGS=($@)
export ARGS[@]

EDIT:
Once you left the loop, the Array *should* be accessible from within the same script, or others if they were sourced.
Even without the export!!

If this doesnt help, please provide code.
# 3  
Old 09-26-2013
Quote:
Originally Posted by periyasamycse
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.
I assume you mean that you're using the Korn shell.

If your array assignments are happening in a subshell environment, the values assigned will not be seen in the original shell environment. (If this is the case sea's suggestion won't help.)

Without seeing your code, we can only waste time guessing at what might be wrong. Please show us your code, explain what you want that code to do, show us the output you want, and show us the output you are getting (including all diagnostic messages). Please also tell us what type of system you're using. (The utilities available and the options available for those utilities varies from system to system.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question