Exercise

Putting Scripts on the PATH Exercise

Task

Give yourself a scripts directory that every new shell can find, so the scripts you write later run by name.

Hosts
workstation, then servera
  1. Inspect the current PATH

    PATH is a list of directories separated by colons. Bash searches them left to right and the first match wins.

    echo $PATH
  2. Find where PATH is already set

    Open ~/.bashrc and search for PATH. Red Hat already customizes it here, which is why /home/student/bin is on your list. You are about to do the same thing a few lines lower.

    less ~/.bashrc
    /PATH
  3. Add a directory for this shell only

    Create the directory and append it to PATH. Naming $PATH on the right keeps everything that was already there.

    mkdir -p ~/scripts
    PATH=$PATH:~/scripts
    echo $PATH
  4. Confirm it disappears in a new session

    Log out of servera and log back in. Nothing wrote that line to a file, so the new session starts without it.

    exit
    ssh servera
    echo $PATH
  5. Persist it in ~/.bashrc

    Add the same line to the end of ~/.bashrc, then log out and back in to confirm a new session picks it up.

    vim ~/.bashrc
    PATH=$PATH:~/scripts
    exit
    ssh servera
    echo $PATH