bash shell: 'exec', 'eval', 'source' - looking for help to understand

Hi, experts.
Whould anybody clear explay me difference and usage of these 3 commands (particulary in bash) :
exec
eval
source

I've tryed to read the manual pages but did not get much.
Also could not get something useful from Google search - just so much and so not exactly, that is is not usefull
Would it be any different result in environment after using any of these command?
Where and for what purpose each should be used?
How and is there any difference to use those from interactive shell or from script?

Greately appreciate your help

eval "translates" a value buried inside a variable, and then runs the command that was buried in there

for i in 1 2 3
do
   eval myvar="$i"
   echo "$myvar"
done
# this gives 
1
2
3
# why? because there is no metavalue or special meaning to 1 or 2 or 3
for i in ls df
do
    eval myvar="$i"
    echo "$myvar"
done
# here you get output from the ls command and the df command

exec starts another process - BUT - it exits the current process when you do this kind of thing

#!/bin/bash

exec echo "leaving this script forever  $0"   # Exit from script here.

# ----------------------------------
# The following line never happens

echo "This echo will never echo."

source

When you run a command in the shell - like another script or a command like ls -
the shell creates a subprocess (called child process). Any environment variable that got defined or changed down in the child is LOST FOREVER to the parent process.

However if you source a script (there are two ways) you force the script to run in the current process. That means environment variables in the script you ran are NOT LOST.

# script1
MYVAR="HI there!"
# end script1
# script2
# first, run script 1
script1
# now is the MYVAR variable set?  No -why? it got set in the child, when the child exited it GOT LOST
echo "MYVAR= $MYVAR"
# now source script1 :: putting a lonesome dot or the command  "source" 
#  in front of the script name have the same effect
. script1
#  . script1 == source script1  these two are the SAME THING
source script1
# now is the MYVAR variable set?  This time we see that MYVAR has a value
echo "MYVAR= $MYVAR"

jim mcnamara -
thank you, very much, everything clear and usefull for me now!

I am realy exiting to understand it. Now I have new (for me ) possibility in scripting and in shell.
Definetely, 'eval' gives usefull opportunity!
The 'exec' - nice to know that and it is good to use it, too.
The 'sorce' - it appeared that I have used it already for long time (as '. script') but did not realized tha all definishions of the curent shell are available in runing script by that (other part - backward - usualy is a reason to use the '. scr')
I've just tryed it and maybe it would be usefull to show it here, too, although your explanation pretty enough, but, anyway, here it is:

bash-802:/home/dca0701/develop/src> cat > try.sh
/usr/bin/echo "\n -- try to use already defined in shell alias:"
ec "<<< this printed by shell alias 'ec'"

shopt -s expand_aliases
alias ec2=ec
ec "--- new alias is declared as ec2"
^C
bash-803:/home/dca0701/develop/src>
bash-803:/home/dca0701/develop/src> chmod 777 try.sh
bash-804:/home/dca0701/develop/src>
bash-804:/home/dca0701/develop/src>
bash-804:/home/dca0701/develop/src> try.sh

 -- try to use already defined in shell alias:
./try.sh: ec: command not found
./try.sh: ec: command not found
bash-805:/home/dca0701/develop/src>
bash-805:/home/dca0701/develop/src> source try.sh

 -- try to use already defined in shell alias:
<<< this printed by shell alias 'ec'
--- new alias is declared as ec2
bash-806:/home/dca0701/develop/src> ec2 hello
hello
bash-807:/home/dca0701/develop/src>

Once again, thank you very much!

One thing that eval does that is critical is break things apart in strings. For example if in a script you wrote lscommand="ls -F", then tried to run $lscommand, the shell would give you an amusing error that it didn't find the command ls -F. If instead you eval $lscommand, it works fine. One place I use that a lot is in a script where some args are to be passed to a command (or commands). I gather them together in variable, such as lsoptions="$lsoptions $arg" At the end of dealing with the arguments, the lsoptions might have for example, "-F -a". If I try to run ls $lsoptions ls will complain about the argument "-F -a" (and you'll get really odd incomprehensible complaints too! If instead, I do eval ls $lsoptions it does just what I wanted. Yea!

Patrick