|
Prev: how to get the hostnames and memory usage biger than 30M?
Next: How to remove common lines from a text file in Korn Shell
From: Mtek on 15 Apr 2008 09:48 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
From: pk on 15 Apr 2008 11:04 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.
From: Wayne on 15 Apr 2008 16:46 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 "$@" 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
From: Geoff Clare on 18 Apr 2008 08:47 Wayne wrote: > In the "environment file" script add: > > [ $# != 0 ] && eval "$@" > > 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(a)gclare.org.uk>
From: OldSchool on 18 Apr 2008 12:32
On Apr 15, 9:48 am, Mtek <m...(a)mtekusa.com> 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 it sounds like he wants the something along the lines of the following env_file =============================== LOG_DIR=/somepath logfile=somefile LOGPATH=$LOG_DIR/$1/$logfile export ...... =============================== then he procedes to do something like: . ./env_file test echo $LOG_PATH /somepath/test/somefile . ./env_file prod /somepath/prod/somefile |