Go Back   The UNIX and Linux Forums > Operating Systems > Solaris


Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-18-2011
presul's Avatar
Registered User
 
Join Date: May 2010
Location: Poland
Posts: 88
Thanks: 2
Thanked 2 Times in 2 Posts
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 07:06 AM..
Sponsored Links
    #2  
Old 06-18-2011
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,146
Thanks: 3
Thanked 957 Times in 936 Posts
Quote:
Originally Posted by presul View Post
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 ~]#

Sponsored Links
    #3  
Old 06-18-2011
presul's Avatar
Registered User
 
Join Date: May 2010
Location: Poland
Posts: 88
Thanks: 2
Thanked 2 Times in 2 Posts
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 ?
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
cat and export steven_TTG UNIX for Dummies Questions & Answers 3 02-27-2009 08:58 PM
Can BASH execute commands on a remote server when the commands are embedded in shell bash_in_my_head Shell Programming and Scripting 1 12-04-2008 12:51 AM
About export Arunprasad Shell Programming and Scripting 3 11-05-2008 02:18 AM
export script commands with xterm chris2051 UNIX for Dummies Questions & Answers 1 10-09-2008 07:15 AM
code that reads commands from the standard i/p and executes the commands Phrozen Smoke Programming 4 01-22-2007 01:06 AM



All times are GMT -4. The time now is 11:34 AM.