How is .profile and environment variable linked..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How is .profile and environment variable linked..
# 1  
Old 12-02-2005
Data How is .profile and environment variable linked..

Smilie
1.) How is .profile and environment variable linked.?
2.) What happens when we execute a script.?
# 2  
Old 12-02-2005
Answer to your first question:
When you login, the various commands in the .profile are run. This may include setting the path, the prompt, and a host of other things. An example .profile:
Code:
PATH=/usr/bin:/usr/sbin:/sbin; export PATH
MANPATH=/usr/share/man:/opt/<some_app>/man; export MANPATH
/usr/games/fortune

The above file will set the PATH and the MANPATH variables in the environment and run the fortune program. This is the way that the .profile and the env variables are linked. It is just a convenient way to customize your environment.

I didn't get the second question. I mean, when you run a script, the various commands in the script are executed. What more?
# 3  
Old 12-02-2005
If that is so, then what is env used for

If that is so, then what is `env` used for ?

1.) where can we find the `env` file ?
2.) When we run `env` command , we find list of things. What is the use of it & How to change it .?
# 4  
Old 12-02-2005
From the man page of env:
Quote:
NAME
env - set environment for command execution

SYNOPSIS
env [-] [-i] [name = value] ... [command [arguments ...]]

DESCRIPTION
env obtains the current environment, modifies it according to its
arguments, then executes the command with the modified environment.
Arguments of the form name=value are merged into the inherited
environment before the command is executed. The -i option causes the
inherited environment to be ignored completely so that the command is
executed with exactly the environment specified by the arguments.
The simplest form of the command is to just run 'env'. This will give you the current environment, which may be used by various commands when they execute. In the more complicated form, the env command can be used to set a specified variable with the given value and that modified variable used in the environment when executing the specified command.

To understand what the above paragraph says, let us take an example (this is for ksh):
Code:
$ export ORACLE_SID=abc; export ORACLE_HOME=/oracle817
$ sqlplus internal
SQL> set pages 1000;
SQL> select name,open_mode from v$database;
NAME      OPEN_MODE
--------- ----------
ABC         MOUNTED
SQL> exit;
$ env ORACLE_SID=xyz sqlplus internal
SQL> set pages 100
SQL> select name,open_mode from v$database;
NAME      OPEN_MODE
--------- ----------
XYZ         MOUNTED
SQL> exit;
$ env|grep ORA
ORACLE_SID=abc
ORACLE_HOME=/oracle817

The above example shows how env can be used to temporarily change the environment for the duration of a single command, without actually modifying the value of the variable.

1) The 'env' command does not read from a file, the environment is stored in the memory. From the man page of environ:
Quote:
The environment of a process is accessible from C by using the global
variable:
char **environ;
2) The use of the 'list of things' that we get from the 'env' command has been explained above, to set the various environment variables, you have to use shell specific syntax.
For sh:
Code:
PATH=/usr/bin; export PATH

For ksh,bash:
Code:
export PATH=/usr/bin

For csh,tcsh:
Code:
setenv PATH /usr/bin

I think that this answers both your questions. Also, read the man pages of env and environ for more indepth explainations.
[/CODE]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Issue Regarding environment/.profile file

Hi All, I have my own .profile file and environment file. To execute some commands I always need to load some module using module command and change my environment files to project environment file (. /some/project/some/path/init.environ).Without changing my environment file to project file,... (2 Replies)
Discussion started by: saps19
2 Replies

2. AIX

Profile environment variables lost after mksysb restore

Hello. I restore an mksysb image (AIX 5.3 TL 11) from one model to another model of Power (power 5 to power 7). Everything seems good, but I lost environment variables of at least one of a user profile. The result of the "env" command show me great differences between two servers, first of them... (2 Replies)
Discussion started by: stephnane
2 Replies

3. Shell Programming and Scripting

Expand an environment variable in sed, when the variable contains a slash

I'm trying to make a sed substitution where the substitution pattern is an environment variable to be expanded, but the variable contains a "slash". sed -e 's/<HOME_DIRECTORY>/'$HOME'/'This gives me the following error: sed: -e expression #1, char 21: unknown option to `s'Obviously this is... (2 Replies)
Discussion started by: Ilja
2 Replies

4. UNIX for Dummies Questions & Answers

defining variable in .profile

In root dir i have created a .profile file and added variable and assigned a path to it: a = '/dir/dir' export a but when i echo (echo $a) the path or use this variable the value or path not getting displayed. i tried executing the .profile and logging out and logging in, didnt workout. am... (1 Reply)
Discussion started by: abhi_n123
1 Replies

5. UNIX for Dummies Questions & Answers

Messed up my boot environment or root profile

Ok, a couple weeks ago I was fixing a cron report about perl not happy with 'locale' info (LANG and LC not set). As a result, I was experimenting with setting the correct 'locale' in several areas (like /etc/sysconfig/i18n and who knows where). Somehow after a reboot, as soon as the OS starts... (3 Replies)
Discussion started by: Garball
3 Replies

6. Shell Programming and Scripting

User profile, environment

Hello , i am on sles 11, and i can't figure out how can i locate my profile file, the one that is use for setting the environment when i log in. oracle@r200:~> cd oracle@r200:~> pwd /opt/oracle oracle@r200:~> echo $SHELL /bin/bash oracle@r200:~> oracle@r200:~> cat .profile cat: .profile:... (4 Replies)
Discussion started by: tonijel
4 Replies

7. AIX

rerun .profile after changing variable

I changed a $variable in my .profile (AIX unix). I know I could exit out and logon onto unix again, but how do I rerun the .profile at the command line? (2 Replies)
Discussion started by: sboxtops
2 Replies

8. AIX

Environment variable values encrption in profile

Hello This is the format of present profile which we use for a AIX user export DMRUNuser ; DMRUNuser="owbrunuser_10" export DMRUNpasswd ; DMRUNpasswd="ods$12345" DMRUNuser&DMRUNpasswd were the environmental users which store the user id and password of a... (1 Reply)
Discussion started by: kalpana.anuga
1 Replies

9. Solaris

Where's the .profile environment config for root under Bourne shell?

I don't know where the environment config file for root user is in the Bourne shell on Solaris 10? Can you help me, or am I helpless???? (2 Replies)
Discussion started by: Joncamp
2 Replies

10. Solaris

Profile and environment variable

Hi, I'm using solaris 8 and I need to know where I can add the following variable to have it applied to all my user Ids. I tried to add this to /etc/profile but not working when i check with "env" command : export PW_MATRIX=/usr/local/ccms/security/dat/.PASSWORD_MATRIX export... (2 Replies)
Discussion started by: unclefab
2 Replies
Login or Register to Ask a Question