passing array variables to spawned shells

passing array variables to spawned shells

Post by Andy Hau » Sat, 26 Mar 2005 04:22:39



hello,

in ksh or bash you can set array vars like
   a[1]=x
   a[4]=y

can you export these so that they are available in spawned shells?
I tried
   export a
and opened a new ksh or bash but the variable is not set there.

on the other hand a
   ( echo ${a[1]} )
in the existing shell works fine.

what am I missing?
what's the difference between running /bin/ksh and a subshell (...)
in context with array variables?

rgds
andreas

 
 
 

passing array variables to spawned shells

Post by Moshe Jacobso » Sat, 26 Mar 2005 06:26:15



> in ksh or bash you can set array vars like
>    a[1]=x
>    a[4]=y
> can you export these so that they are available in spawned shells?

The very last line of the bash-2.05b man page says:

    Array variables may not (yet) be exported.

I suggest taking a look at bash 3.0 to see if it allows you to do
that.

Moshe

--
*** SPAM BLOCK: Remove bra before replying! ***
http://runslinux.net :: moshe at runslinux dot net :: AIM: Jehsom

 
 
 

1. How to pass a variable from a shell script to another shell script...

Hi,
         I have written a shell script 1............and internally its
calling another shell script 2........input to  redhat specific
chkconfig command... which executes and builds links in bootstartup
scipt directories (rc.d).

Actually i needs to pass a variable $DIRECTORY  of my command available
( can hard code but i am
setting it in the 1st script) to the 2nd script how to pass that... As
the setting is happening before the calling of
shell script2, i just tried like putting  echo "$DIRECTORY" into the 2nd
shell script, which is not working is there
a way to get the functionality.

shellscript1:
#!/bin/sh
---------
---------
---------
DIRECTORY="/sbin/ntp"
---------
---------
/sbin/chkconfig "shellscript2"
---------

shellscript2:
#!/bin/sh
-------
echo "$DIRECTORY"     <------put to see whether getting the value here
or not..

$DIRECTORY   -c ntp.conf          <------if it is so ,  i could use like
this.................

thanks,
srinivas.

--
office ph: 091-40-3607619

2. Xtops.DE: Linux Laptops for Students (June)

3. Setting variables in a variable array of null variables

4. HELP-8-bit not clean error

5. How can i pass an shell Array to sql Session ?.

6. ftp broken pipe

7. Does the RH 5.1 Bash shell support array variables?

8. Please help!Video or Monitor incompatibilty problem

9. Expanding a shell variable that may contain shell variables.

10. How to represent an array of variables in shell script?

11. How do I make/use bourne shell array variables?

12. environment variables passing to another shell (script)

13. Passing variables as arguments to commands in a shell script