Sponsored Content
Operating Systems Solaris export vs env vs set commands Post 302531834 by presul on Saturday 18th of June 2011 07:00:32 AM
Old 06-18-2011
export vs env vs set commands

Hi

I'm trying to understand variable scopes in solaris10.
It is said that to display env variables we use 3 commands :
- env
- set
- export

What is the difference between them ?

thx for help.

---------- Post updated at 11:00 AM ---------- Previous update was at 10:50 AM ----------

I understand this :

To list all shell vars with their current values perform set cmd.
Code:
# set
HOME=/root
HZ=
IFS=

LC_COLLATE=pl_PL.ISO8859-2
LC_CTYPE=pl_PL.ISO8859-2
LC_MESSAGES=C
LC_MONETARY=pl_PL.ISO8859-2
LC_NUMERIC=pl_PL.ISO8859-2
LC_TIME=pl_PL.ISO8859-2
LOCAL=local_variable
LOGNAME=root
MAIL=/var/mail/root
MAILCHECK=600
OPTIND=1
PATH=/usr/sbin:/usr/bin
PS1=#
PS2=>
REMOTE=remote_variable
SHELL=/sbin/sh
TERM=ansi
TZ=Poland

To make a value of variable known to a subshell export it using the export cmd.
Code:
# export
export LOGNAME
export PATH
export REMOTE

QUESTIONS
---------------
Now I understand the difference between set and export cmds but don't understand the meaning of env command ?
What does it mean to make a value of variable known to a sub-shell ?

Last edited by presul; 06-18-2011 at 08:06 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

set env in login file

Hi, I have inserted the following line in my local.login file setenv ORACLE_HOME /u01/app/oracle/product/8.1.7 Then when I do an echo $ echo $ORACLE_HOME I get a blank line. Am I setting up ORACLE_HOME incorrectly? Thanx (3 Replies)
Discussion started by: nattynatty
3 Replies

2. Shell Programming and Scripting

Reason for EXPORT in .profile,env,etc

Hi all, I have seen it in all the .profile files and env file this PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:. export PATH What exactly does this Export path does?? Thanks SUmeet (1 Reply)
Discussion started by: sumeet
1 Replies

3. Shell Programming and Scripting

export env variables

hi i want to write a shell script to set environment variables . But i am not been able to set that for the current shell instead i have to spawn a new shell. Is there a way to set the env variable for the current shell using shell script in bash shell ? Thnx (2 Replies)
Discussion started by: varun.81
2 Replies

4. UNIX for Advanced & Expert Users

How to export ENV variables, which remains set for all the shell

Hi ! How to export ENV variables, which remains set for all the shell Example :- Login :myID Pwd : **** -> Here my ID .profile is executed. Let say I set MYENV variable Kisses% rlogin ABC -l XXXGroupID -> I login into a remote Solaris Server ABC password : **** -> "XXXGroupID's... (1 Reply)
Discussion started by: dashok.83
1 Replies

5. UNIX for Dummies Questions & Answers

set env variables in a new xterm

Hi, I have a script that sets some env variables. I want to source the script in a new xterm and after the script execution is over, the xterm has to be alive with the env variables set according to the script. I tried xterm -e "source ./myscript;tcsh" & The variables are getting set... (3 Replies)
Discussion started by: chaitubek
3 Replies

6. Solaris

How to set PS1 in env

Hello whenenver i login to solaris server the prompt is displaying as #. i want to customize the promt with server name for all users. how to customize the PS1 variable for all the users?. Thanks for your help in advance. regards, Saravana (2 Replies)
Discussion started by: tsaravanan
2 Replies

7. Shell Programming and Scripting

Set/Export Env Vars from with Shell Script With Input Variable

I have a shell script I want to run that will set environment variables based on the value of an input variable submitted when the shell script is called. For example: $ mgenv.sh prod This would set environment variables for prod $ mgenv.sh test This would set environment variables... (1 Reply)
Discussion started by: brtaylor73
1 Replies

8. Shell Programming and Scripting

export and access env variable in two scripts

Hi, I have two scripts say one.sh and two.sh. I want one.sh to continuously export a variable in loop. and when two.sh starts then it should read the last value exported from one.sh. file: one.sh #! bin/sh for i in `seq 1 1 4000000`; do export VAR=$(($i**$i)) ; done file two.sh ... (2 Replies)
Discussion started by: bhushan123
2 Replies

9. Red Hat

Set Env

Hi, I need to add file the /usr/lib under the command set. The /usr/lib need to be set under the DIRS=' ' while listing the set command. I tried with the command below: export PATH=${PATH}:/usr/bin But this doesn't work out... (4 Replies)
Discussion started by: gsiva
4 Replies

10. Shell Programming and Scripting

BASH script to export var to env

Hi all I am trying to create a script that takes a password input then writes that to a tmp file and puts that tmp file path in my env as a var. It does everything but export the my env and I am unsure why. I am using Ubuntu 12.4 #!/bin/bash read -s -p "Enter Password: " gfpassword... (5 Replies)
Discussion started by: koikoi
5 Replies
ENV(1)							    BSD General Commands Manual 						    ENV(1)

NAME
env -- set and print environment SYNOPSIS
env [-i] [name=value ...] [utility [argument ...]] DESCRIPTION
env executes utility after modifying the environment as specified on the command line. The option name=value specifies an environmental variable, name, with a value of value. The option '-i' causes env to completely ignore the environment it inherits. If no utility is specified, env prints out the names and values of the variables in the environment, with one name=value pair per line. EXIT STATUS
env exits with one of the following values: 0 utility was invoked and completed successfully. In this case the exit code is returned by the utility itself, not env. If no util- ity was specified, then env completed successfully and returned the exit code itself. 1 An invalid command line option was passed to env. 1-125 utility was invoked, but failed in some way; see its manual page for more information. In this case the exit code is returned by the utility itself, not env. 126 utility was found, but could not be invoked. 127 utility could not be found. COMPATIBILITY
The historic - option has been deprecated but is still supported in this implementation. SEE ALSO
execvp(3), environ(7) STANDARDS
The env utility conforms to IEEE Std 1003.2-1992 (``POSIX.2''). BUGS
env doesn't handle commands with equal (``='') signs in their names, for obvious reasons. BSD
June 8, 2007 BSD
All times are GMT -4. The time now is 03:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy