![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Goto last visted directory | prasanth_babu | SUN Solaris | 6 | 08-11-2008 12:17 AM |
| Stuck after typing goto | rairey | UNIX for Dummies Questions & Answers | 2 | 09-20-2007 10:19 AM |
| Use of GOTO statement in scripts | vikasduhan | Shell Programming and Scripting | 7 | 02-02-2006 08:50 AM |
| GOTO LOOP in KORNE SHELL | DeepakXavier | Shell Programming and Scripting | 1 | 11-10-2005 08:47 AM |
| how to goto in ksh | Geraldine | Shell Programming and Scripting | 4 | 03-12-2004 04:35 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
goto statement
I have a test script for using goto statement but its not working. please help
i tried both in linux and hp-ux it's not working please help #! /bin/ksh t=`ps -ef|grep ti.sh|grep -v grep` if [ $? -eq 0 ]; then goto start else goto stop fi start: echo "start" stop: echo "stop" |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
As already mentioned, a goto statement doesnt exist in a Korn Shell. Instead you could define 2 functions. Code:
#! /bin/ksh
start()
{
echo "start"
}
stop()
{
echo "stop"
}
t=`ps -ef|grep t[i].sh`
if [ $? -eq 0 ]
then
start
else
stop
fi
The "grep -v grep" was wrong in this scenario anyway. Because when you check for the return code "$?", you actually check the return code of the command "grep -v grep" and not of the command "grep ti.sh". |
|
|||
|
Quote:
Sometimes goto statements can make the code more efficient, cleaner and concise. Linus about the use of goto's: Quote:
|
|
||||
|
According to the rules:
(8) No BSD vs. Linux vs. Windows or similar threads. And that applies to arguing about goto's as well. The question has been answered so I will close this thread. |
||||
| Google The UNIX and Linux Forums |