Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Dec 2001 15:29:57 -0800 (PST)
From:      Philip Hallstrom <philip@adhesivemedia.com>
To:        freebsd-questions@freebsd.org
Subject:   How can I set an environment variable for /bin/sh scripts (ie. cron?)
Message-ID:  <20011219152607.R59071-100000@teak.adhesivemedia.com>

next in thread | raw e-mail | index | archive | help
Hi -
	I am going nuts trying to figure out how to set an environment
variable that will be accessable to my cron scripts...  Part of the
problem is that the variable needs to be user-specific (ie. read from say
~/.profile).  And I can't change my scripts to source $HOME/.profile
either. So...

Reading the /bin/sh man page I came across this:

--------------------------------------------------------------------------
A login shell first reads commands from the files /etc/profile and then
.profile if they exist.  If the environment variable ENV is set on entry
to a shell, or is set in the .profile of a login shell, the shell then
reads commands from the file named in ENV.  Therefore, a user should
place commands that are to be executed only at login time in the
.profile file, and commands that are executed for every shell inside the
ENV file.  The user can set the ENV variable to some file by placing the
following line in the file .profile in the home directory, substituting
for .shinit the filename desired:

    ENV=$HOME/.shinit; export ENV

The first non-option argument specified on the command line will be
treated as the name of a file from which to read commands (a shell
script), and the remaining arguments are set as the positional
parameters of the shell ($1, $2, etc).  Otherwise, the shell reads
commands from its standard input.

Unlike older versions of sh the ENV script is only sourced on invocation
of interactive shells.  This closes a well-known, and sometimes easily
exploitable security hole related to poorly thought out ENV scripts.
--------------------------------------------------------------------------

That last paragraph seems to say that there isn't any way to do what I
want, but I can't believe there isn't any way to do this...

Any and all help appreciated!

thanks!

-philip


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011219152607.R59071-100000>