export vs env vs set commands


 
Thread Tools Search this Thread
Operating Systems Solaris export vs env vs set commands
# 1  
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 09:06 AM..
# 2  
Old 06-18-2011
Quote:
Originally Posted by presul
What does it mean to make a value of variable known to a sub-shell ?
Code:
[root@linux ~]# x=5                       <= here variable is set without export command
[root@linux ~]# echo $x
5
[root@linux ~]# bash                      <= subshell creation
[root@linux ~]# echo $x                   <= subshell doesnt know $x variable value

[root@linux ~]# exit                      <= exit from subshell
exit
[root@linux ~]# echo $x                   <= parent shell still knows $x variable
5
[root@linux ~]# export x=5                <= specify $x variable value using export command
[root@linux ~]# echo $x                   <= parent shell doesn't see any difference from the first declaration
5
[root@linux ~]# bash                      <= create subshell again
[root@linux ~]# echo $x                   <= now the subshell knows $x variable value
5
[root@linux ~]#

# 3  
Old 06-18-2011
ok @bartus11 I understand now the difference but have one more question :

Command set shows all declared variables, command export shows only declared and exported variables but what shows env command ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question

Featured Tech Videos