Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I control flow in a horn shell script ?

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
I need to create a korn shell script with many steps
BUT
each step must only run if the previous step completes successfully.
How do I code that ?
 
hi Tison

unix commands return a value when they finish, you can pick up this value like this
[tt]
somecommand[tab][tab]# do something
retval=$?[tab][tab][tab]# pick up the value returned by 'somecommand'
 
You can try...
[tt]
comm1 && comm2 && comm3 && comm4
[tt]
... and it will run [tt]comm1[/tt] and if it returns 0 (true) then will run [tt]comm2[/tt] and if it returns 0 (true) then will run [tt]comm3[/tt] ... et cetera, or you can try
[tt]
command1
if [ $? ]
then
command2
if [ $? ]
then
command3
if [ $? ]
then
command4
fi
fi
fi
[/tt]

I hope it works...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top