Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Console Foundations Environment and Redirection Environment Variables

Sam Purcell
Sam Purcell
2,121 Points

Why does /home/treehouse/bin still show up in the path when we close the tab or even exit the console and reload?

I thought the point of adding the export into the .bashrc file was so this would happen because it isn't saved anywhere when we just do it from the command line?

1 Answer

Nathan Williams
seal-mask
.a{fill-rule:evenodd;}techdegree
Nathan Williams
Python Web Development Techdegree Student 6,851 Points

good question, Sam. To understand what's happening here, you have to know a little bit about how the bash environment works, and how workspaces works on the backend.

Commands in your ~/.bashrc are evaluated like a normal bash command you might put in a shell script. "export" is what's called a "shell builtin", (so is "cd". you can tell the difference by running "type $command" at a shell prompt) which just takes a variable, and makes it available to other programs. You can see this with the "env" program, which dumps the environment to stdout.

[nathwill@wyrd ~]$ var=val
[nathwill@wyrd ~]$ env | grep ^var
[nathwill@wyrd ~]$ echo $var
val
[nathwill@wyrd ~]$ export var=val
[nathwill@wyrd ~]$ env | grep ^var
var=val
[nathwill@wyrd ~]$ echo $var
val

so, export makes an environment variable available to other programs. this is nice if you want to, say, have your $PATH inherited by any programs you run. to permanently add something to your shell sessions, it's common to add these types of commands to a file that gets sourced when the session starts, like ~/.bashrc or ~/.profile.

workspaces is a bit of a special case though, because the entire environment is reset after every launch, with only your files under ~/.local, and ~/workspaces being persisted between workspace sessions. You can see this because if you add something to your ~/.bashrc, close out the workspace and wait about 15 minutes to relaunch it (there's an idle timeout before the workspace is reaped), whatever you added to the ~/.bashrc will not be there in the new session.

hope that helps!

Sam Purcell
Sam Purcell
2,121 Points

Very helpful, thanks Nathan!