Exec Cmd In Shell Scripting


overjupiter

Still Fresh
Joined
Nov 9, 2005
Messages
54
I was wondering why this works
Code:
#!/bin/sh
# return to the menu screen
cd /usr/gp2x
exec /usr/gp2x/gp2xmenu

but this doesn't
Code:
#!/bin/sh
# return to the menu screen
exec /usr/gp2x/gp2xmenu

is there a reason you have to change to the directory before running exec ?
 
Yes it looks for files relative to the current path.

btw exec replaces your script with the program you give, so nothing you put after it will run, even after the program exits.
 
theoddbot posted on Dec 6 2005 at 03:00 AM said:
Yes it looks for files relative to the current path.

btw exec replaces your script with the program you give, so nothing you put after it will run, even after the program exits.

It annoys me to no end seeing people not use exec in real life; every day I watch people log into a machine, and "tcsh" since they prefer that over bash or so or whatever shell they've got assigned; nice waste of memory, since they really shoudl be doing "exec tcsh" since they do not intend to return. Imagine seeing 40 peopel logged into a machine, most of them doing that.. *arg* :)

"exec" is good :)

jeff
 
Last edited by a moderator:
Back
Top