0

According to the BASH Reference Manual:

export

export [-fn] [-p] [name[=value]]

    Mark each name to be passed to child processes in the environment.

An example I've come across:

PS1=<\u\h \W>\$

export PS1

What I've gleaned from the documentation, and examples, is that export is used to permeate a change in the environment across multiple shells? My confusion comes form the numerous times I have not seen it used in similar circumstances, yet everything remains working as intended.

E.g, I created an environment variable to track the load order of my profile files. Here is an example from my .bashrc file:

PROFILE_ORDER="$PROFILE_ORDER:~/.bashrc"

and it produces this behavior

$ echo $PROFILE_ORDER
/etc/bash.bashrc:~/.bashrc

If my understanding of export is correct, then why didn't I need to use it in creating and modifying $PROFILE_ORDER?

0

export is used to set variable which is accessible from a shell executed from your current shell.

> x=1
> export y=2
> echo $x $y
1 2
> bash
> echo $x $y
2

.bashrc is executed every time when you open new shell, so if I set y=2 there, it would be known in every new shell without using export

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.