The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
environment variable sharanbr Shell Programming and Scripting 8 06-12-2007 05:43 AM
Environment variable values encrption in profile kalpana.anuga AIX 1 02-13-2007 10:46 PM
Where's the .profile environment config for root under Bourne shell? Joncamp SUN Solaris 2 12-02-2006 01:22 AM
Profile and environment variable unclefab SUN Solaris 2 05-12-2005 06:57 AM
Modifying $PATH variable in /etc/profile Deepali UNIX for Dummies Questions & Answers 3 03-12-2001 09:17 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-02-2005
Registered User
 

Join Date: Sep 2005
Posts: 22
Unhappy How is .profile and environment variable linked..


1.) How is .profile and environment variable linked.?
2.) What happens when we execute a script.?
Reply With Quote
Forum Sponsor
  #2  
Old 12-02-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
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?
Reply With Quote
  #3  
Old 12-02-2005
Registered User
 

Join Date: Sep 2005
Posts: 22
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 .?
Reply With Quote
  #4  
Old 12-02-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
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]
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0