1833053 Members
2580 Online
110049 Solutions
New Discussion

Re: about exit

 
SOLVED
Go to solution
thebeatlesguru
Regular Advisor

about exit

when i use "exit" in > ,it could exit the system,but if i write a shell script:
#!/bin/sh
exit

it could not exit system,so i wanna know what command i can use in shell to exit system,not exit shell
hihi
6 REPLIES 6
Deepak Extross
Honored Contributor

Re: about exit

If your shell script is called myexit.sh, try calling it like this:
. myexit.sh
rather than just
myexit.sh

Hope this helps.
Steven Sim Kok Leong
Honored Contributor
Solution

Re: about exit

Hi,

Insert the following statement in your script where you want to exit the system:

kill -9 `ps -fp $PPID|awk '{print $2}'|tail -1`

Hope this helps. Regards.

Steven Sim Kok Leong
Deepak Extross
Honored Contributor

Re: about exit

using 'logout' instead of 'exit' should work too.
thebeatlesguru
Regular Advisor

Re: about exit

i know that could use logout instead of exit

however ,steven,can u explain the statement :
kill -9 `ps -fp $PPID|awk '{print $2}'|tail -1`

i cant understand it exactly


hihi
Steven Sim Kok Leong
Honored Contributor

Re: about exit

Hi,

Actually the following is sufficient in your script:

kill -9 $PPID

PPID (parent process id) is PID (process id) of the login shell (parent) spawning off your shell script (child process)

Hope this helps. Regards.

Steven Sim Kok Leong
Tom Burba
Occasional Advisor

Re: about exit

Only root has rights to do this. How can a user do it?
UNIX is like an ocean... (anonymous)