Sponsored Content
Top Forums Shell Programming and Scripting Passing variables between scripts Post 302157530 by bbergstrom74 on Friday 11th of January 2008 06:29:15 AM
Old 01-11-2008
Passing variables between scripts

Hi all.

I need to pass a value from a script that runs in a sub-shell, back into the calling shell like below (or into script 2 directly):

outer_script
export param=value1

script1 $param
(in script1: export param=value2)

script2 $param
($param is now value1, not value2 like i'd prefer)
end outer_script

I can't get this to work using regular variables and I have read some about shells and sub-shells and variables and I now believe that it's not possible with variables.

I guess I could always use a file to store the value in script1 and then read it in script2 using the file. But if I go this way I'd be forced to have separate files for each user that executes the script so that no conflicts occurr. But then I'd get a lot of files that mess up. I guess I could then remove each file after the script completes but what if the user terminates using Ctrl+C? I'd still have a lot of messy files after a while.

At the moment I'm leaning towards using files, but I thought I'd ask if someone knows another/better way to do this without using files?

This is in Korn Shell
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing variables

Hi, Is there any way to pass variable to a sed script.For awk we have -v option.like that do we have any way to pass variable to a sed script from a awk script or from normal script? Thanx, sounder (1 Reply)
Discussion started by: sounder123
1 Replies

2. Shell Programming and Scripting

Passing Vars between scripts

Im running a script that runs scripts within it self and i need to pass vars made in the original script to scripts run within it and the only way i can think to do it is right the string to a file and read the file in the script (4 Replies)
Discussion started by: rcunn87
4 Replies

3. Shell Programming and Scripting

Passing and using arguments in Scripts.

I am new to scripting in AIX / UNIX. I have a script that runs 4 other scripts and I want to be able to pass in a agrument that I can check before I run the next script to see if the previous script finished with no errors. Can someone send me an example of this as I'm sure it's pretty easy to... (1 Reply)
Discussion started by: David.Vilmain
1 Replies

4. UNIX for Dummies Questions & Answers

Passing variables between scripts...

Hey all, I'm wondering how you pass variable's that are defined in one script to another script that's been called by that first script..... Best regards, Jaz (1 Reply)
Discussion started by: Jazmania
1 Replies

5. Shell Programming and Scripting

Perl parameter passing between scripts

Hi All, I have two perl scripts say A.pl and B.pl. A.pl interacts with Database and pulllls around 20 column-variables, which needs to be used in B.pl . A.pl calls B.pl, I figured out that there exist a limit on number of arguments being passed as command line argument. A.pl writing to a... (3 Replies)
Discussion started by: coolbhai
3 Replies

6. Shell Programming and Scripting

Passing Arguments in Shell Scripts

Hello everybody! First time posting here:) Right, I am trying to pass arguments in my shell scripts using $1, $2 and $3 etc using if else statement........ This is my shell script which is based on serching the google website #!/bin/sh wget -t1 -E -e robots=off - -awGet.log -T 200 -H... (47 Replies)
Discussion started by: kev_1234
47 Replies

7. Shell Programming and Scripting

Passing variables between sub-scripts

I have written a program for some data analysis. It is gettin long. I would like to restructure it so that i can have a master file which controls multiple subscripts in order to make it easier to understand. I need to be able to define variables in the master script which are used by all three... (2 Replies)
Discussion started by: carlr
2 Replies

8. Shell Programming and Scripting

General question about passing variables among shell scripts

So this is something I've been wondering how to do for a while. Suppose I have two shell scripts a.sh and b.sh script a does some function and outputs to a varable $x . I would then like to take $x into the second function, b.sh, and do a function on it and create some output. So how do you pass... (3 Replies)
Discussion started by: viored
3 Replies

9. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

10. Shell Programming and Scripting

Passing parameters with spaces between scripts

I have 2 scripts. test.sh, which calls submit2.sh. One of the parameters contains space and is quoted. ((((./submit2.sh Group_1_2_AMS_DAILY_CORE_GRP03 AMS AMS_D 'DAILY REPORT PROCEDURES'; echo $?>&3) | tee 1.log >&4)3>&1) | (read xs; exit $xs)) 4>&1 echo parm 1 = $1 echo parm 2 = $2... (1 Reply)
Discussion started by: andyclam
1 Replies
pkgparam(1)							   User Commands						       pkgparam(1)

NAME
pkgparam - display package parameter values SYNOPSIS
pkgparam [-v] [-d device] [-R root_path] pkginst [param...] pkgparam -f filename [-v] [param...] DESCRIPTION
pkgparam displays the value associated with the parameter or parameters requested on the command line. The values are located in either the pkginfo(4) file for pkginst or from the specific file named with the -f option. One parameter value is shown per line. Only the value of a parameter is given unless the -v option is used. With this option, the output of the command is in this format: parameter1='value1' parameter2='value2' parameter3='value3' If no parameters are specified on the command line, values for all parameters associated with the package are shown. OPTIONS
Options and arguments for this command are: -d device Specify the device on which a pkginst is stored. It can be a directory pathname or the identifiers for tape, floppy disk, or removable disk (for example, /var/tmp, /dev/diskette, and /dev/dsk/c1d0s0). The special token spool may be used to rep- resent the default installation spool directory (/var/spool/pkg). -f filename Read filename for parameter values. -R root_path Defines the full path name of a subdirectory to use as the root_path. All files, including package system information files, are relocated to a directory tree starting in the specified root_path. -v Verbose mode. Display name of parameter and its value. OPERANDS
pkginst Defines a specific package instance for which parameter values should be displayed. param Defines a specific parameter whose value should be displayed. ERRORS
If parameter information is not available for the indicated package, the command exits with a non-zero status. EXIT STATUS
0 Successful completion. >0 An error occurred. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
pkgmk(1), pkgproto(1), pkgtrans(1), pkginfo(4), attributes(5) Application Packaging Developer's Guide NOTES
With the -f option, you can specify the file from which parameter values should be extracted. This file should be in the same format as a pkginfo(4) file. For example, such a file might be created during package development and used while testing software during this stage. SunOS 5.10 6 Nov 2000 pkgparam(1)
All times are GMT -4. The time now is 03:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy