Visit Our UNIX and Linux User Community


accessing a variable or array of one script in another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting accessing a variable or array of one script in another
# 1  
Old 10-24-2009
accessing a variable or array of one script in another

hi all, i've a requirement like this.

i want to access the contents of an array declared in one script,which is a bash script, to a second script which is a perl script.

actually i want a sort of global variable which can be accessed in other script
like environmen variables and also i can unset them whenever i need!!

plz help me...

thanks in advance..
regards..
# 2  
Old 10-24-2009
perl has a builtin hash containing shell variables. you can access anything in the parent shell like so
Code:
# for a shell variable named 'VAR' the value of '$VAR' is accessed thusly:
$ENV{'VAR'};

# 3  
Old 10-25-2009
thanx varontron !! but my actual problem is stated below!!
here is the script sample1.sh
Code:
#!/bin/bash
tab=$1;
declare -a ${tab}_fld;
for((i=1;i<=4;i++))
do
   echo -n "enter ${tab}_fld[$i] :";read ${tab}_fld[$i];
done

eval echo \${${tab}_fld[3]};

 export  ${tab}_fld;
 export tab;
 perl -e '
   $tab="$ENV{'tab'}"."_fld";
   print ("$tab\n");
  print ("env: $ENV{'"$tab[3]"'} \n");
 '

Code:
$ ./sample1.sh hell
enter hell_fld[1] :1
enter hell_fld[2] :2
enter hell_fld[3] :3
enter hell_fld[4] :4
3
syntax error at -e line 4, near "hell["
Execution of -e aborted due to compilation errors.

i want to access the 'hell_fld' array declared above.
infact, i want access the array in sample1.sh through another script like ..
Code:
#!/usr/bin/perl
$tab="$ENV{'tab'}"."_fld";
 print ("$tab\n");
 print ("env: $ENV{'"$tab[3]"'} \n");

is there any way to make this possible? plz help.

thanx!!
# 4  
Old 10-27-2009
no replies yet.....plz help somebody.

Previous Thread | Next Thread
Test Your Knowledge in Computers #247
Difficulty: Easy
By 1973, the File Transfer Protocol (FTP) specification had been defined (RFC 354) and implemented, enabling file transfers over the ARPANET.
True or False?

10 More Discussions You Might Find Interesting

1. AIX

Oracle output to an array variable in script

Hi- I am returning output of an query into a array variable in my shell script. set -A DATE_RANGE `sqlplus -s **/**@** << EOF set termout off set echo off set serveroutput off set pagesize 0 set linesize 500 set heading off set verify off set feedback off select... (1 Reply)
Discussion started by: vputtas@gmail.c
1 Replies

2. Shell Programming and Scripting

Script to store the variable in a table or array.

Hi, I have few variable say 10 ex:- l_pc_291334_01_0_01_00.cmp l_pc_441133_50_0_02_00.cmp l_pc_441133_55_0_02_00.cmp Each variable value is coming via loop on a table. I want to create a script that stores these value to a table or array ( But one by one not all at one time as... (4 Replies)
Discussion started by: amitkumar.b2
4 Replies

3. Shell Programming and Scripting

Problem accessing array elements

Hi all, I can’t resolve an array element access issue on (Linux/pdksh) .. So I’m positing for advice.By the way - a friend demonstrated to me - same script works as expected under Solaris. I have been working on a documentation project where many *.jpg screen shots are used in the... (4 Replies)
Discussion started by: njdpo
4 Replies

4. Shell Programming and Scripting

Accessing a variable from another script

Hi, Can anyone assist me on how to access a variable in a shell script from another script. for ex, Script-1 ------- #! /bin/sh c=10 Where as, i would like to access the velue of variable c in another script 'Script-2'. Thankyou to all in advance !! :b: :b: (2 Replies)
Discussion started by: little_wonder
2 Replies

5. Shell Programming and Scripting

Accessing array elements

Hi, My doubt is how to access array elements.. Situation is as below: #!/bin/ksh set -x typeset -i x=0 typeset -i y=0 typeset -i BID=0 typeset -i count=0 while ] ; do x=`expr $x + 1`; hwmgr show scsi > scsi.tmp while read line; do set... (1 Reply)
Discussion started by: mansa
1 Replies

6. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

7. Shell Programming and Scripting

Accessing awk array from shell

Hi, i want awk to read a file and place it's content into two arrays. When trying to read these arrays with a "for a in ${source_path} "-Loop it gives the right result. But when trying to access directly (/bin/echo ${source_path}) it doesn't work. I read "all "the awk threads in this forum and... (6 Replies)
Discussion started by: bateman23
6 Replies

8. Shell Programming and Scripting

Accessing single elements of a awk array in END

How do I access one of the indices in array tst with the code below? tst=sprintf("%5.2f",Car / 12) When I scan thru the array with for ( i in tst ) { print i,tst } I get the output of: vec-7 144 But when I try this in the END print tst It looks like it's not set. What am... (6 Replies)
Discussion started by: timj123
6 Replies

9. UNIX for Dummies Questions & Answers

accessing shell script variable in file

Hi, I have a shell script in which there is a file conn_$temp where $temp has the pid of the shell script. in this shell script i have an embedded awk script that must read the file while ((getline < "conn_$temp") > 0) However due to the "$temp" in the file name, the awk script is... (6 Replies)
Discussion started by: HIMANI
6 Replies

10. Shell Programming and Scripting

accessing my first element of array

Hello everyonel, I have an array set like so num=4 read name arr=name I go through while loop to assign different values to different array element from 1 to 4. when I try to access the FIRST element of the array I get the last one first. Like if I say ${arr} it will show the last element... (4 Replies)
Discussion started by: afadaghi
4 Replies

Featured Tech Videos