- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Korn Shell question
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
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-20-2011 01:14 AM
тАО05-20-2011 01:14 AM
how do I exit a script from a function that is called as var=$(
The following example always prints "x: 1" whereas I would expect it to exit in the test1 function and thus only print "1"
"
#!/usr/bin/ksh
function test1
{
echo "1"
exit 1
}
x=$(test1)
echo "x: $x"
"
I tested this on Linux with zsh running as ksh and on HP-UX 11.11.
Any help much appreciated.
Kris
Solved! Go to Solution.
- Tags:
- ksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-20-2011 02:19 AM - last edited on тАО06-29-2021 04:48 AM by Ramya_Heera
тАО05-20-2011 02:19 AM - last edited on тАО06-29-2021 04:48 AM by Ramya_Heera
SolutionKris,
Well it would never just print "1" as the command substitution you are using is assigning that value to x rather than echoing it to the terminal.
from the man page for ksh :
Command substitution of most special commands (built-ins) that do not
perform I/O redirection are carried out without creating a separate
process. However, command substitution of a function creates a
separate process to run the function and all commands (built-in or
otherwise) in that function.
So when you do command substitution - $()of a function that runs in a seperate process, so the exit call just exits that other process and returns to the main parent shell script process.
Generally I use "return" in functions rather than "exit" and then test the return value from the function to decide what to do...
Obviously this is a "constructed" test - what are you actually trying to acheive here?
HTH
Duncan
I am an HPE Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-20-2011 03:11 AM
тАО05-20-2011 03:11 AM
Re: Korn Shell question
I just ran into this problem when I was reviewing code from somebody else where the script just continued after an exit 1 in a function that was used in cmd substitution.
I will need to change the logic of the script a bit and like you suggested test for the return code.
Thanks for your help