Best way to setup my own environmental variables ?


 
Thread Tools Search this Thread
Operating Systems AIX Best way to setup my own environmental variables ?
# 1  
Old 03-09-2010
Question Best way to setup my own environmental variables ?

I am writing a few korn scripts to be used by all our operators on several 4.1/4.2 AIX servers.

I want to create environmental variables that once set, can be read/modified by my scripts (ex: specific folders, file names, conventions, general values, ...). I thought this would be better then simply retyping them in all my scripts and would make maintenance a lot easier.

What would be the best way to do this ?

My scripting level is beginner but mainly because I am very rusty (used to do it a few years back).
# 2  
Old 03-09-2010
One method would be to define common variables in a library file and source it in at the start of the script.
# 3  
Old 03-09-2010
Source them. You write an extra file that contains your standard variables and just source it in all scripts where you need them like:

Code:
#/bin/bash

. ./myenv

# here comes the rest of my script
...
...

This way you can also write libraries that contain functions you often use. You can include those external scripts all by using the dot and a blank before the script to be sourced.

---------- Post updated at 04:43 PM ---------- Previous update was at 04:42 PM ----------

As leebix says - sorry I was too slow, got interrupted while writing Smilie
# 4  
Old 03-09-2010
but what if some of those variables need to have their content changed everyday ?

Most of my intended variables won't change their contant but some will.

ex:
we have a specific file that we use each day in a few tasks. The name is somewhat different everyday. So I want to create an environment variable that will contain that name and be able to change that name everyday so when my script use that variable (by no matter which operator), they will have the right filename in them.
# 5  
Old 03-09-2010
Another option for functions (when using ksh*) is the FPATH variable.

[* Note that in AIX /bin/sh is the same binary as ksh. I know this is true for 5.x and later, verify for yourself on 4.x. Also note that you can use ksh syntax even when called as sh.]

This allows you to maintain a directory of function "files" that will be autosourced when needed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

<< Environmental Variables are not set when script completes >>

Hi Team, I have a wrapper script which i have pasted below, it internally calls one python script to generate Environmental in a file called /home/oracle/myenv.sh, when i execute this script via wrapper script, its not reflecting in my current session, still showing old env variables. any... (2 Replies)
Discussion started by: kamauv234
2 Replies

2. OS X (Apple)

Don't understand the practical difference between command aliases and environmental variables

Hey, I'm recently learning Unix from the video course by Kevin Scoglund. I'm stuck at the moment where he goes into Environmenat variables. I have some issues with understanding what's the essential difference between EV and command aliases: for instance, by writing the command alias ll='ls... (3 Replies)
Discussion started by: scrutinizerix
3 Replies

3. Shell Programming and Scripting

Help with manipulating environmental variables in UNIX

I am wondering if there is away to increment a date in c shell. What I need to do is basic, but I lack the knowledge. I have they following environmental variable in my job scripts setenv YYYY `date '+%Y'` I then set YYYY to be part of my output dataset name: setenv dd_OUTPUTP... (1 Reply)
Discussion started by: jclanc8
1 Replies

4. Shell Programming and Scripting

Oracle environmental variables in shells script

Hi, Getting below error on executing the shell script which initiates sqlplus How to set oracle enviornment variables in the shell script ? With Regards (3 Replies)
Discussion started by: milink
3 Replies

5. Shell Programming and Scripting

[bash] command line substitution with environmental variables

Hi, I'm using an array that contains compiler FLAGS that need to be executed either before ./configure or after the main 'make' command. example of array containing compiler flags. ------------------------------------------------- FLAGS="CFLAGS=\"-arch x86_64 -g -Os -pipe... (7 Replies)
Discussion started by: ASGR
7 Replies

6. UNIX for Dummies Questions & Answers

Unix passing environmental Variables

In my script when I change an env variable in the parent shell it is only changed for that session - it there away to change it permanently using a script so that when I use rlogin (create a child session) that the env variable is set correctly? Basically what I am trying to do is to pass a... (7 Replies)
Discussion started by: belfastbelle
7 Replies

7. AIX

NIM server setup on etherchannel setup environment

I know that IBM's official stance is that NIM does not work on etherchannel environment, but has anyone able to get around it? I'm working on a p5-590 LPAR system, and the NIM master and clients are all on the same frame. Any help is appreciated. (1 Reply)
Discussion started by: pdtak
1 Replies

8. Shell Programming and Scripting

Environmental Variable

Hi, I'm exporting an environmental variable from a C program using putenv function. I'm calling the exe of the C program from shell script. But when I display the environmental variables from the Shell script, My varaible is not getting displayed. Can anyone please tell me how to get it in... (2 Replies)
Discussion started by: janemary.a
2 Replies

9. UNIX for Advanced & Expert Users

Environmental Variables - where stored ?

Hi all ! Yesterday I defined an environmental variable PATH, but today when I restarted machine, I could not see that it was stored any place. Is there any file where I could save the settings ? I have quite a few env.variables defined, so I need a smarter way to define. regards D (5 Replies)
Discussion started by: DGoubine
5 Replies

10. UNIX for Dummies Questions & Answers

environmental varibles

flavor -- AIX 4.2.1 I am putting together some HTML pages, some of which contain forms. The problem pops up when I attempt to pass variables (from the forms) from one HTML page to a cgi-like page created using ksh. I have used the $1 - $9 vars, but they do not work with the passing. With... (1 Reply)
Discussion started by: Xiix
1 Replies
Login or Register to Ask a Question