

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Compiled vs. Interpreted
incomplete
2: Executables
incomplete
3: Shebang
incomplete
4: Bourne Shell
incomplete
5: Environment Variables
incomplete
6: PATH
incomplete
7: Change Your PATH
incomplete
This lesson's interactive features are locked, please to keep using them
We talked about how you can create and use local variables in your shell:
name="Lane"
echo $name
# Lane
There is another type of variable called an environment variable. They are available to all programs that you run in your shell.
You can view all of the environment variables that are currently set in your shell with the env command.
To set a variable for your current shell session, use the export command (it won't persist if you close the terminal):
export NAME="Lane"
You can then use the variable in your shell, just as before:
echo $NAME
# Lane
The interesting part is that programs and scripts you run in your shell can also use that variable:
For example, if we have a script called introduce.sh with the following contents:
#!/bin/sh
echo "Hi I'm $NAME"
We can run it and it will use the NAME environment variable we set earlier:
./introduce.sh
# Hi I'm Lane
You can also temporarily set a variable for a single command, instead of exporting it for the whole session.
For example:
WARN_MESSAGE="this works too" bash worldbanc/private/bin/warn.sh
You can use the unset command to remove an environment variable from your current shell session:
unset NAME
Take a look at the contents of the worldbanc/private/bin/warn.sh script. It looks like it's supposed to print nicely formatted warning messages with worldbanc branding...
Submit the shell checks.