# export vs env vs set commands

**URL:** <https://community.unix.com/t/export-vs-env-vs-set-commands/290029>\
**Category:** Solaris\
**Created:** [June 18, 2011, 7:00am UTC](https://community.unix.com/t/export-vs-env-vs-set-commands/290029 "2011-06-18T07:00:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![presul](https://community.unix.com/user_avatar/community.unix.com/presul/32/1936_2.png) [@presul](https://community.unix.com/u/presul)\
**Post date:** [June 18, 2011, 7:00am UTC](https://community.unix.com/t/export-vs-env-vs-set-commands/290029/1 "2011-06-18T07:00:32Z")

</div>

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.

```nohighlight
# 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.

```nohighlight
# 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 ?

---

<div class="post-metadata">

**Author:** ![bartus11](https://community.unix.com/user_avatar/community.unix.com/bartus11/32/1418_2.png) [@bartus11](https://community.unix.com/u/bartus11)\
**Post date:** [June 18, 2011, 7:34am UTC](https://community.unix.com/t/export-vs-env-vs-set-commands/290029/2 "2011-06-18T07:34:32Z")

</div>

> [@presul](#):
>
> What does it mean to make a value of variable known to a sub-shell ?

```plaintext
[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 ~]#

```

---

<div class="post-metadata">

**Author:** ![presul](https://community.unix.com/user_avatar/community.unix.com/presul/32/1936_2.png) [@presul](https://community.unix.com/u/presul)\
**Post date:** [June 18, 2011, 2:00pm UTC](https://community.unix.com/t/export-vs-env-vs-set-commands/290029/3 "2011-06-18T14:00:21Z")

</div>

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 ?
