Environment Files

Hi,

We have an environment file that gets included at the top of every
script we have. At this time, we want to be able to pass a parameter
to that environment file and create a variable based on it.

Is this possible? The environment file is nothing but variable
declarations. Can this be done so I can create a variable like:
$LOG_DIRECTORY/$parameter/$logfile_name

Thanks!

John
mtek [ Di, 15 April 2008 15:48 ] [ ID #1942525 ]

Re: Environment Files

On Tuesday 15 April 2008 15:48, Mtek wrote:

>
> Hi,
>
> We have an environment file that gets included at the top of every
> script we have.

By sourcing it?

> At this time, we want to be able to pass a parameter
> to that environment file and create a variable based on it.
>
> Is this possible? The environment file is nothing but variable
> declarations. Can this be done so I can create a variable like:
> $LOG_DIRECTORY/$parameter/$logfile_name

These above are variables already defined in the file? Please provide an
example input, with expected output or result.
PK [ Di, 15 April 2008 17:04 ] [ ID #1942530 ]

Re: Environment Files

Mtek wrote:
> Hi,
>
> We have an environment file that gets included at the top of every
> script we have. At this time, we want to be able to pass a parameter
> to that environment file and create a variable based on it.
>
> Is this possible? The environment file is nothing but variable
> declarations. Can this be done so I can create a variable like:
> $LOG_DIRECTORY/$parameter/$logfile_name
>
> Thanks!
>
> John

In the "environment file" script add:

[ $# != 0 ] && eval "$ [at] "

Then if the parameter is:

. env_file foo=bar

That should set the variable foo to the value bar in the
current environment. (when you said "included" I assume
you meant "sourced".)

But it seems to me this is not the best solution to whatever
your problem is. What is the real problem for which you think
this mechanism is the solution? I bet this group can come up
with suggestions for you to solve your problem a better way.

-Wayne
wayne [ Di, 15 April 2008 22:46 ] [ ID #1942540 ]

Re: Environment Files

Wayne wrote:

> In the "environment file" script add:
>
> [ $# != 0 ] && eval "$ [at] "
>
> Then if the parameter is:
>
> . env_file foo=bar
>
> That should set the variable foo to the value bar in the
> current environment. (when you said "included" I assume
> you meant "sourced".)

The OP didn't specify a particular shell, so we should assume a
portable solution is wanted. Not all shells support passing
parameters when sourcing (it's not required by POSIX).

--
Geoff Clare <netnews [at] gclare.org.uk>
Geoff Clare [ Fr, 18 April 2008 14:47 ] [ ID #1945038 ]

Re: Environment Files

On Apr 15, 9:48=A0am, Mtek <m... [at] mtekusa.com> wrote:
> Hi,
>
> We have an environment file that gets included at the top of every
> script we have. =A0At this time, we want to be able to pass a parameter
> to that environment file and create a variable based on it.
>
> Is this possible? =A0The environment file is nothing but variable
> declarations. =A0Can this be done so I can create a variable like:
> $LOG_DIRECTORY/$parameter/$logfile_name
>
> Thanks!
>
> John

it sounds like he wants the something along the lines of the following

env_file
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D

LOG_DIR=3D/somepath
logfile=3Dsomefile

LOGPATH=3D$LOG_DIR/$1/$logfile
export ......
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D

then he procedes to do something like:

=2E ./env_file test
echo $LOG_PATH
/somepath/test/somefile

=2E ./env_file prod
/somepath/prod/somefile
OldSchool [ Fr, 18 April 2008 18:32 ] [ ID #1945042 ]
Linux » comp.unix.shell » Environment Files

Vorheriges Thema: cd is not working as expectd
Nächstes Thema: Help required:Awk Error