- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: "goto" equivalent in shell script
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-2003 05:52 AM
тАО05-14-2003 05:52 AM
my question is: is there an operation allowed in shell script language that has the same output as "goto" in C++? lets assume that i've written a command, its output is either 0 or 1, in case it's 1, i'd like to continue running the script from line of a certain number - that's what i need "goto" for.
thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2003 06:01 AM
тАО05-14-2003 06:01 AM
Re: "goto" equivalent in shell script
function task1{
echo "hello world"
done
}
##########################################################################
# Main Program #
##########################################################################
case $1 in
hello ) task1 ;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2003 06:06 AM
тАО05-14-2003 06:06 AM
Re: "goto" equivalent in shell script
check for the 'break' statement which can be used for the same.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2003 06:07 AM
тАО05-14-2003 06:07 AM
Re: "goto" equivalent in shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2003 06:08 AM
тАО05-14-2003 06:08 AM
Solutionfunction myfunction {
script stuff
}
while blah blah blah....
do
myfunction
done
if [ blah blah ]
then
myfunction
fi
you can call that same function at any time in the script which will work as a "goto" of sorts.
the case (as also mentioned above) will let you do a similar thing as the function... but call various things.... I use this when creating a menu in a script.
The below excert from one of my scripts is written as a function... but also has a case statement used.
function user_grp {
clear
echo " Enter the user you wish to assign to a group:\c"
read user
clear
echo " Assign $user into a group"
echo " ${BOLD}1${NORMAL} - ART-ISC"
echo " ${BOLD}2${NORMAL} - GTS"
echo " ${BOLD}3${NORMAL} - SAP"
echo " ${BOLD}4${NORMAL} - Telecoms"
until [ "$group" = "1" ] || [ "$group" = "2" ] ||
[ "$group" = "3" ] || [ "$group" = "4" ] ; do
echo "Please select one of the menu options"
read group
done
case $group in
1)
grp=ART-ISC
;;
2)
grp=GTS
;;
3)
grp=SAP
;;
4)
grp=Telecoms
;;
esac
echo "$user:$grp:n:*" >> ~/scmauth/auth
mxauth -a -f ~/scmauth/auth
echo "authorization complete"
echo "$user added to $grp on all servers"
echo "$user was added to $grp on all servers by `logname` on `date` " >> ~/scmauth/auth.added.log
more auth >> auth.granted
rm auth
touch auth
sleep 5
~/scmauth/scm_menu
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2003 06:10 AM
тАО05-14-2003 06:10 AM
Re: "goto" equivalent in shell script
Although there may be a goto statement it's not a particularly nice way to program!
How about something like:
your_user_command
if [[ $? -eq 0 ]]
then
do stuff for command outputting 0
else
do stuff for command outputting 1
fi
or you could use functions to separate it out. You may need to rethink the script; but it will be more structured and easier to follow.
regards,
Darren.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2003 06:14 AM
тАО05-14-2003 06:14 AM
Re: "goto" equivalent in shell script
There is a bit to learn to change the way you approach this problem. That's why we're here :) glad to help with any scripting questions you may have.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2003 06:19 AM
тАО05-14-2003 06:19 AM
Re: "goto" equivalent in shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2003 06:26 AM
тАО05-14-2003 06:26 AM
Re: "goto" equivalent in shell script
Strange thing with scripting.
. script
Will not fork but continue at the same level.
Thus you can even
if [[ $? -eq 0 ]]
then
. scriptres0
else
. scriptres1
fi
And insert small scripts into your script depending on the result.
Steve Steel