Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

passing variables from on script to another

1 view
Skip to first unread message

Derk

unread,
Mar 15, 2006, 11:14:13 AM3/15/06
to
How do I pass variables from one scrip to another.

I dont want to call the second script from the first with the variables on
the 'command l

I really want to set an environment variable in script1 and pick it up in
script2, but I can't get it to work

script1=

-----------------------------------------------
dk=derrick
echo $dk
script2
-----------------------------------------------

script2 =

-----------------------------------------------
echo $dk


script 1 echos derrick, but script 2 does not??

thanks

derrick


James Carlson

unread,
Mar 16, 2006, 7:28:23 AM3/16/06
to
"Derk" <derric...@bradford.gov.uk> writes:
> script 1 echos derrick, but script 2 does not??

If script 1 calls script 2, then add "export dk" and it will work.

If script 1 does not call script 2 (i.e., they're both called by some
other process, and neither calls the other, or script 2 calls script
1), then it cannot be done.

--
James Carlson, KISS Network <james.d...@sun.com>
Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677

Michael Paoli

unread,
Mar 16, 2006, 9:42:55 AM3/16/06
to
Derk wrote:
> How do I pass variables from one scrip to another.
> I dont want to call the second script from the first with the variables on
> the 'command l
> I really want to set an environment variable in script1 and pick it up in
> script2, but I can't get it to work
examples/references:
$ cat first
foo=foo
$ cat second
#!/bin/sh
echo foo="$foo"
$ (unset foo; . first; . second)
foo=foo
$ (unset foo; . first; export foo; ./second)
foo=foo
$ ed first
8
s/^/echo /
$a
echo export foo
.
w
29
q
$ cat first
echo foo=foo
echo export foo
$ (unset foo; eval `./first`; ./second)
foo=foo
$
sh(1)
fork(2)

Frank J. Perricone

unread,
Mar 16, 2006, 10:56:13 AM3/16/06
to
On 16 Mar 2006 07:28:23 -0500, James Carlson <james.d...@sun.com>
wrote:

> If script 1 does not call script 2 (i.e., they're both called by some
> other process, and neither calls the other, or script 2 calls script
> 1), then it cannot be done.

You could kluge something similar by having some temp file that script 1
writes, and then script 2 reads it and puts it into its envvar.

--
Frank J. Perricone fr...@dlc.state.vt.us
IT Manager 802-828-4926 Fax: 802-828-2803
Vermont Department of Liquor Control http://www.state.vt.us/dlc/

aasim...@gmail.com

unread,
Mar 16, 2006, 3:19:06 PM3/16/06
to
try using 'export'

e.g

myvar2="Joe Blow"
export myvar2
./script2

----- script2

echo "Who is $myvar2"

*** this is bourne shell

0 new messages