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"

There is no goto statement in ksh. Other shells support it, for example, tcsh.

With all respect, a goto statement is for those who cannot program. It is a "dirty" way to jump from 1 place in the code to another.

As already mentioned, a goto statement doesnt exist in a Korn Shell.

Instead you could define 2 functions.

#! /bin/ksh

start()
{
  echo "start"
}

stop()
{
  echo "stop"
}

t=`ps -ef|grep t.sh`
if [ $? -eq 0 ]
then
  start
else
  stop
fi

By putting "" around 1 letter of the search pattern in the grep command there is no more need for the "grep -v grep" command.

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".

Or:

ps -ef|grep [t]i.sh>&-&&echo start||echo stop

With some shells you'll get an error with the above operation (closing fd1),
so redirecting fd1 to /dev/null will be more portable,
and, of course, with GNU grep you can use the "q" option.

Never seen the Linux Kernel source code?
Sometimes goto statements can make the code more efficient, cleaner and concise.

Linus about the use of goto's:

Regards

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.