passing a variables value from the called script to calling script using ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing a variables value from the called script to calling script using ksh
# 8  
Old 06-19-2008
# script1
tmp=`script2 $1 $2`
RESULT=$?
if (($RESULT != 0 )) then
exit $RESULT
fi
set $tmp
print $1 $2 $3


#script2
if [[ $TEST = "" ]] then
print myparms $1 $2
else
exit 1
fi


# After the following step we expect to see "myparms par1 par2"
script1 par1 par2
#set TEST to fail script2
export TEST=YES
script1 par1 par2
print script1 exit code is $?
unset TEST

Last edited by odashe; 06-19-2008 at 03:11 PM..
# 9  
Old 06-19-2008
Sorry, I don't understand your example or it does not meet my requirement.

1. Second script does not have any variable set and that variable is not displayed in the first script.
2. We also need to check whether the 2nd script run fine or not.
# 10  
Old 06-19-2008
No. Script2 runs first.
# 11  
Old 12-23-2008
Hi,

In this thread a code was suggested by Jim in this manner

Code:
#inside child script
mypid=$$
echo "PID=$mypid" > /tmp/pidfile
# the pid of the child is now recorded in /tmp/pidfile

Code:
#parent process
tmp=$(child.ksh 1 2 3 )
# now read the file child.ksh wrote
chmod +x /tmp/pidfile 
. /tmp/pidfile
# The variable PID is now defined in the parent

I have a couple of questions:
1. Is the /tmp/ directory automatically created?
2. from the parent script, what does this line do:
tmp=$(child.ksh 1 2 3 )
does it re-execute the child.ksh script?
3. is it ./tmp/pidfile or is there really a space there?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Weird issue - *ksh script not recognized when being called

HI Team - I'm running into a weird issue when trying to call a .ksh script. In my shell script, I'm using the following command to call my environment file: cd /hypbin/test ./_env.ksh But it's saying not found. Permissions are set correctly, shebang is set but I'm unsure why it's not... (5 Replies)
Discussion started by: SIMMS7400
5 Replies

2. Shell Programming and Scripting

Passing stdin value into a script that is called from another script

I'm trying to automatically pass user input values into a script that is being called from another script, below is my current script and I added a comment next to the script where it asks user to enter input value. Thanks, mbak #!/bin/ksh echo " Adding disks for DB server then Enter YES... (2 Replies)
Discussion started by: mbak
2 Replies

3. Shell Programming and Scripting

Calling bash script works when called manually but not via Cron?

Hi, I've got a Bash backup script I'm trying to run on a directory via a cron job nightly. If I ssh in and run the script manually it works flawlessly. If I set up the cron to run evertything is totally messed up I don't even know where to begin. Basically the path structure is ... (6 Replies)
Discussion started by: wyclef
6 Replies

4. Shell Programming and Scripting

Passing variable from called script to the caller script

Hi all, Warm regards! I am in a difficult situation here. I have been trying to create a shell script which calls another shell script inside. Here is a simplified version of the same. Calling Script. #!/bin/ksh # want to run as a different process... (6 Replies)
Discussion started by: LoneRanger
6 Replies

5. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

6. Shell Programming and Scripting

Passing the value of variable which is read from command line in called script

Hi, I am calling a Perl script in my shell script. When Perl script is executed it asks for a answer to be entered by user from terminal. How can i pass that value from my shell script ?? I know I can change perl script to default the answer but i dont have access to do that so only option i... (5 Replies)
Discussion started by: varun22486
5 Replies

7. UNIX and Linux Applications

Calling script - Called script concept.

Hi Guys, I am new to unix and would like to know the basics about calling a shell script from another shell script. I would like to know if the calling script can finish in any way before the called script actually gets executed completely. I want this to happen :cool: For Example :... (1 Reply)
Discussion started by: khedu
1 Replies

8. Shell Programming and Scripting

How to return the value from the called shell script to the calling sh script

Hi all, I have two ksh scripts #sample1.sh #!/bin/ksh . ./sample2.sh echo $fileExist #sample2.sh #!/bin/ksh func() { i=1 return $a } func echo $? Here how should I return the value of sample2.sh back to sample1.sh? Thanks in advance. (2 Replies)
Discussion started by: gp_singh
2 Replies

9. Shell Programming and Scripting

Need help with ksh script that uses sqlplus, called from PHP

I have a ksh script that connects to sqlplus and dumps the query results into a file. The script works file when I run it from the command line, however, when I call it from PHP using system(), exec(), or shell_exec() commands, the script doesn't seem to run the query. It will create the text file... (7 Replies)
Discussion started by: j2owilson
7 Replies

10. Shell Programming and Scripting

passing variables to awk from ksh script

I'm trying to write a ksh script that uses awk, but I want to pass variables to awk. For example (not working): if ];then searchstr=$1 lsof -i | awk '{if($9~/SEARCHSTR/) print $2} SEARCHSTR=$searchstr' else echo "usage: $0 <search string>" fi I tried several options. Is it... (3 Replies)
Discussion started by: rein
3 Replies
Login or Register to Ask a Question