- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- global variables in ksh
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2002 05:05 AM
тАО05-14-2002 05:05 AM
global variables in ksh
child shell in the parent shell. Kind of global variables in all other program lanugages.
Anyhelp would be appreciated.
Suppose if I have script like this
-- Listing of a one.ksh
#!/bin/ksh
status=0
(
echo "Inside the sub shell"
echo "Call a Sample program "
./sample.ksh
status=$?
echo value of the status inside the
sub shell $status
)
echo value of the status outdside
subshell $status
-- Listing of sample.ksh
ls xyz > /tmp/one.txt
$./one.ksh
Inside the sub shell
Call a Sample program
xyz not found
value of the status inside the sub
shell 2
value of the status outdside subshell 0
thanks.
-- David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2002 05:20 AM
тАО05-14-2002 05:20 AM
Re: global variables in ksh
You could try something like this...
(
my_script.sh
echo $?
) | read retval
echo "Return code was $retval"
But of course you'd have to make sure that nothing in the sub-shell sent anything to stdout or stderr.
HTH
Duncan
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2002 05:21 AM
тАО05-14-2002 05:21 AM
Re: global variables in ksh
You can SOURCE the child process in the parent process:
. ./sample.ksh
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2002 06:00 AM
тАО05-14-2002 06:00 AM
Re: global variables in ksh
You can try this:
#!/bin/ksh
status=0
(
echo "Inside the sub shell"
echo "Call a Sample program "
./sample.ksh
status=$?
echo value of the status inside the sub shell $status
exit $status
)
status=$?
echo value of the status outdside subshell $status
Above, I just capture the "status" value that I've set inside the sub-shell with the 'exit' command.
Good Luck!
Rumagoso
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2002 06:19 AM
тАО05-14-2002 06:19 AM
Re: global variables in ksh
# Create PID dependant temp file names
TDIR=${TMPDIR:-/var/tmp}
PID=${$}
TFILE1=${TDIR}/X${PID}_1.tmp
export TFILE1
child.sh
STAT=$?
# child.sh would then write whatever it wants to the exported pathname ${TFILE1}
# now read the temp file for three variables
if [ ${STAT} -eq 0 -a -f ${TFILE1} ]
then
read A B C < ${TFILE1}
fi
rm -f ${TFILE1}
Multiple child processes could write to separate temp files.
Using the exit status of a child process is very limited; you can only return a limited rangle of NUMERIC values and you can only return at most 1 value. The temp file method is much more flexible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2002 06:41 AM
тАО05-14-2002 06:41 AM
Re: global variables in ksh
parent1.ksh
#!/usr/bin/ksh
./child1.ksh
. ./child1.vars
echo "value of my_gotit is " $MY_GOTIT
echo "value of my_path is " $MY_PATH
child1.ksh
#!/usr/bin/ksh
export MY_GOTIT=99962
export MY_PATH=/path/to/nowhere
env | grep "^MY_" >child1.vars
Note, that in the PARENT1.KSH script, the use of ". ./child1.vars" this SOURCE's in the variables created by the CHILD process. Also note that I used MY_ as a prefix for my variable names so that in the CHILD process I can grep them easily out of the command returned by env.
You might also want to use the CHILD's PID as a suffix for the child.vars filename making it unique for the instance it is running.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2002 08:17 AM
тАО05-14-2002 08:17 AM
Re: global variables in ksh
I'll go ahead and use temp file logic.
-- David