>_ IzzyLab

Hands-on task

This task is step 8 of the course “New server: setup from scratch”

Shop mode in the environment

medium~7 min

The shop's scripts decide whether this is the production or the test server by the environment variable SHOP_MODE. Make sure that every login session of any user has the variable SHOP_MODE=live, and in the environment specifically (programs you start must see it). Set it up system-wide, not by editing everyone's .bashrc.

What you'll practise:
  • environment variables
  • export
  • /etc/profile.d
  • login session
  • printenv

Topic breakdown

Environment variables are context a process inherits from its parent. To give a variable to all users, it's set not in a personal ~/.bashrc but system-wide: when a login session starts, bash reads /etc/profile, which sources every *.sh script from /etc/profile.d/. The difference between a "shell variable" and an "environment variable" is export: without it the value is visible only to the shell itself, and child programs (scripts, printenv) won't get it. It's handy to check with su - user: the dash gives you a real login session.

What's checked

  1. SHOP_MODE=live in the environment of root's login shell
  2. SHOP_MODE=live for a regular user

What it looks like