HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Pass Variables to the second script
Operating System - HP-UX
1828346
Members
3239
Online
109976
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
11-03-2002 08:35 PM
11-03-2002 08:35 PM
I would like to write a script that will execute another script by passing variable as parameter. e.g.
usage s1 a b
#s1
echo $1 $2
v=$1
s2 $v $2
#s2
echo $1 $2
but the result is null.
Rgds,
Stephen
usage s1 a b
#s1
echo $1 $2
v=$1
s2 $v $2
#s2
echo $1 $2
but the result is null.
Rgds,
Stephen
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2002 09:12 PM
11-03-2002 09:12 PM
Solution
When a process terminates i.e. script1, it passes back an 'exit status' to it's parent process. An exit status is actually a number between 0 and 255. The shell stores the last exit status it received in the $? metacharacter.
So adding say exit $? to your script should keep the 'exit status' for the next script.
So adding say exit $? to your script should keep the 'exit status' for the next script.
Anyone for a Mutiny ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2002 09:33 PM
11-03-2002 09:33 PM
Re: Pass Variables to the second script
Here is a nice piece of code I borrowed.
XXX=`somecommand.sh`
STAT=$?
Now $STAT is the exit status of somecommand.sh while $XXX contains its output.
This also should be extended to functions within your scripts.
somefunc()
{
FUNCSTAT=0
echo "This is somefunc output \c:"
while [ $# -ge 1 ]
do
echo "Arg ${1} \c"
shift
done
echo
return(${FUNCSTAT})
}
XXX=`somefunc 111 222`
STAT=$?
Here the same rules as above apply. Typically, you test the exit(return) status before ever doing anything with the script(function) output.
XXX=`somecommand.sh`
STAT=$?
Now $STAT is the exit status of somecommand.sh while $XXX contains its output.
This also should be extended to functions within your scripts.
somefunc()
{
FUNCSTAT=0
echo "This is somefunc output \c:"
while [ $# -ge 1 ]
do
echo "Arg ${1} \c"
shift
done
echo
return(${FUNCSTAT})
}
XXX=`somefunc 111 222`
STAT=$?
Here the same rules as above apply. Typically, you test the exit(return) status before ever doing anything with the script(function) output.
Anyone for a Mutiny ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2002 11:30 PM
11-03-2002 11:30 PM
Re: Pass Variables to the second script
Michael,
It works.
Tks,
Stephen
It works.
Tks,
Stephen
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP