Linux Labs

First steps / Stage 14 of 15

Help and the shell

Not running Starting usually ~20 s
Leave the lesson

Step 5 of 8 · on a machine · 4 min

A setting for new shells

To make lab-status work by name, you add ~/tools to PATH. One command is enough, until you close the terminal.

The directory goes at the front of the list, and echo shows it first:

bash
export PATH="$HOME/tools:$PATH"
echo "$PATH"

To the right of = come the new directory, a colon and the old value $PATH, so the old directories stay in the list. Writing PATH="$HOME/tools" without :$PATH would replace the whole list, and ls and cp would stop being found. export passes the value on to the programs this shell starts.

This setting lasts while this terminal is open: after a new login PATH is back to the old value. Every new interactive Bash runs the commands in ~/.bashrc, so permanent settings are appended to the end of that file. You can add a line in Vim or with >> from the lesson “Where a command's output goes”.

source ~/.bashrc runs the file in the current shell, so an edit takes effect at once. Values from earlier attempts stay in that shell too, though, so the final check is a new login.

Check yourself 1 question

You ran export PATH="$HOME/tools:$PATH", then started a new shell with bash, and lab-status works in it. What does that prove?

  • The new bash inherited PATH from the shell where you ran export — the file played no part. Look at it: tail -n 3 ~/.bashrc.

  • export changes the environment of one shell and the programs it starts. Other terminals and users do not see it.

  • export lives in this terminal's shells. After a new login PATH is back to the old value unless ~/.bashrc has the line.

export passes PATH on to child processes, and the new bash inherited it. The line in ~/.bashrc is tested by a shell with a clean environment, as after a new login — which is how the exercise below checks it.

Key points

  • export PATH="$HOME/tools:$PATH" puts the directory at the front of the list and keeps the old directories.
  • export works in this shell and the programs it starts; for every new login the line goes into ~/.bashrc.
Ubuntu 24.04
Loading…