[Techtalk] probably a stupid scripting question

Miriam English mim at miriam-english.org
Sun Nov 8 06:25:54 UTC 2009


Hi folks,

I was altering a script and wondered what exec did.
The description I read in the documentation I looked up:
"Execute command in place of the current process (instead of creating a 
new process)."
doesn't make a lot of sense to me so I did what I usually do when faced 
with something I don't understand -- I experimented. I created a very 
simple script to see what it did.

echo "blah1"
sleep 5
echo "blah2"
exec sleep 5
echo "blah3"

I kinda thought it would have a delay between printing "blah1" and 
"blah2", but no delay between "blah2" and "blah3", but it doesn't. It 
delays both times, but doesn't print "blah3".

So now, confounded, I do the other thing I do when faced with something 
I don't understand: find someone who might explain it to me. :)

Can anybody give me a simple explanation of what exec does? Am I right 
that the exec'ed command takes over current process and if that process 
is (was) a script, then the script is no longer executing?
If so, what use is that? I notice a lot of application icon scripts use 
exec. Why not use "&" at the end of a command instead? That way the 
script could do other things and end leaving the command to continue on 
its merry way.

Thanks,

	- Miriam

-- 
If you don't have any failures then you're not trying hard enough.
  - Dr. Charles Elachi, director of NASA's Jet Propulsion Laboratory
-----
Website: http://miriam-english.org
Blog: http://miriam_e.livejournal.com


More information about the Techtalk mailing list