Skip to content

export Command

The export command lets you specify whether to export shell variables. So what does this mean?

Variables you create in Linux are valid only in the shells they were created in. In the example below, a variable named "rehber" is created and the value is "gnuadmin". Next, the value of this variable is written to the screen. Afterwards, switching to a different shell and it is seen that the value of the variable cannot be read. Finally, exiting the newly opened shell:

variable without export
ali@gnuadmin:~$ rehber=gnuadmin
ali@gnuadmin:~$ echo $rehber
gnuadmin
ali@gnuadmin:~$ bash
ali@gnuadmin:~$ echo $rehber

ali@gnuadmin:~$ exit
exit
ali@gnuadmin:~$ 

Now let's perform the same scenario using the export command:

export example
ali@gnuadmin:~$ export rehber2=export_edildi
ali@gnuadmin:~$ echo $rehber2
export_edildi
ali@gnuadmin:~$ bash
ali@gnuadmin:~$ echo $rehber

ali@gnuadmin:~$ echo $rehber2
export_edildi

As you see; while the non-exported "rehber" variable cannot be reached, the value of the exported "rehber2" variable can be reached.