- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How can i exit a script when a sentence is true in...
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
Forums
Discussions
Discussions
Discussions
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
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-10-2006 09:42 AM
05-10-2006 09:42 AM
i have a script .. which is using a function as follows:
!#/usr/bin/sh
command1 ..
command2 ..
function ...
command3 ..
command4 ...
how can i do to finish the script when a sentence is true into function?
i mean ..
if i sentence is true into function, how can i break the script, i mean finishe it without run command3 and command4? with exit? with break? what command do i must use ....?
Thanks,
Manuales
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2006 10:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2006 10:11 AM
05-10-2006 10:11 AM
Re: How can i exit a script when a sentence is true into a function?
check(){
if [ "$1" = "bye" ]; then
echo "Bye Bye"
exit 0
fi
}
echo hello
echo hello
check hello
echo hello
echo hello
check bye
echo hello
echo hello
If you run the script you will get:
hello
hello
hello
hello
Bye Bye
That is, two hello before check, first check is false so won't exit, two more hello, second check is true so it exits and the last two hello are not printed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2006 10:15 AM
05-10-2006 10:15 AM
Re: How can i exit a script when a sentence is true into a function?
There are many ways to accomplish this but here is one approach:
Your function should have an explicit return statement
myfunct()
{
typeset -i FSTAT=0
if [[ ${1} -gt 5 ]]
then
FSTAT=1
fi
return ${FSTAT}
} # myfunct
typeset -i STAT=0
command1
command2
myfunction 10
STAT=${?} # capture status of last command/function
if [[ ${STAT} -ne 0 ]]
then
exit ${STAT}
fi
command3
command4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2006 10:24 AM
05-10-2006 10:24 AM
Re: How can i exit a script when a sentence is true into a function?
thanks !!! :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2006 02:20 AM
05-11-2006 02:20 AM
Re: How can i exit a script when a sentence is true into a function?
THAT WORKED !!!
THANK YOU VERY MUCH !!!!
:0)
Manuales.