executing shell script from the cron

This isn't the usual problem that a shell script runs from the command line and not the cron. It's a little different.

Among other things, the shell scrip executes my .profile to set a bunch of variables. It then does an env to ensure that it ran OK.

There are echos in the shell script and the .profile. All this gets logged.

The shell script (simplified) looks like this:

echo Start of shell script
echo
.
.
.
/home/me/.profile

echo Results of env =
env

echo
echo End of shell script

The log (simplified) looks like this:

Start of shell script

----------- (these echos are from the .profile)
profile started

variables a b c x y z set
a=yes
b=yes
c=yes
x=yes
y=yes
z=yes

profile ended
------------------------

Results of env =

a=no
b=yes
c=no
--------

end of shell script

I can see from the log that it is executing the correct .profile, however, the variables set in the .profile aren't "retained".

If I change the command to :

. /home/me/.profile
^
Note: added . space

everthing runs fine.

So what's does the . space do that makes it work?

NORM,

. file
is known as sourcing a file.

It will pull any env settings, or variables set within the file into the current shell.

[ Normal behaviour is for a child process to inherit from a parent, not the other way around, which is why you lost your settings previously]

steve

Thanks, Steve. (Didn't know about inheritance)