Register to get access to free programming courses with interactive exercises

Environment variables Basics of Bash

Video may be blocked due to browser extensions. In the article you will find a solution to this problem.

Important notes

Note that the correct way of creating new variables is without any spaces: VAR=42, not VAR = 42 or VAR =42 or VAR= 42.

Permissions and execution

If you try to create your own bash-script file and run it, Bash will complain about permissions. The reason is, your new text file is not set to be an executable program. Learn more about permissions from Wikibooks or just google "unix permissions".

To quickly fix your issue, do chmod +x your_bash_script_file. This will add executable to your file's permissions, and you'll be able to run it.

Program in the working directory

./program just means "run program that is located in the working directory". . stands for the working directory, and / is just a part of the path, same as in /home/something.

If your program's location is in PATH variable already, then you don't need to add ./ even if you're in the same directory with the program, because Bash already knows where to look for your program.

Lesson notes

  • env to view environment variables
  • VAR=value to set a new environment variable named VAR with value value (e.g. BUILDING_NAME=Tory)
  • echo $VAR to print out the value of VAR
  • VAR=value ./myscript to run myscript bash script file so that it knows the VAR variable
  • export VAR=value to export a variable to all sessions (it will appear in the env list)
  • PATH=/home/joe/apps:$PATH to add /home/joe/apps to the PATH variable. Bash will look inside /home/joe/apps when searching for commands and programss from now on.

Hexlet Experts

Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

About Hexlet learning process

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.bookmate">Bookmate</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.healthsamurai">Healthsamurai</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.dualboot">Dualboot</span>
<span class="translation_missing" title="translation missing: en.web.courses.lessons.registration.abbyy">Abbyy</span>

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions

Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.