Bookmark this page

Guided Exercise: Changing the Shell Environment

In this exercise, you will use shell variables and variable expansion to run commands and set an environment variable to adjust the default editor for new shells.

Outcomes:

You should be able to:

  • Edit user profile.

  • Create a shell variable.

  • Create an environment variable.

Log in to workstation as student using student as the password.

On workstation, run the lab edit-shell start command. This script verifies that the target server is running.

[student@workstation ~]$ lab edit-shell start
  1. Change the student user's PS1 shell variable to [\u@\h \t \w]$ (remember to put the value of PS1 in quotes and put in a trailing space after the dollar sign). This will add the time to the prompt.

    1. On workstation, use the ssh command to log in to servera.

      [student@workstation ~]$ ssh student@servera
      ...output omitted...
      [student@servera ~]$ 
    2. Use Vim to edit the ~/.bashrc configuration file.

      [student@servera ~]$ vim ~/.bashrc
    3. Add the PS1 shell variable and its value to the ~/.bashrc file. Remember to include a trailing space at the end of the value that you set and put the entire value in quotes, including the trailing space.

      ...output omitted...
      # User specific environment and startup programs
      PATH="$HOME/.local/bin:$HOME/bin:$PATH"
      PS1='[\u@\h \t \w]$ '
      export PATH
    4. Exit from servera and log in again using the ssh command to update the command prompt.

      [student@servera ~]$ exit
      logout
      Connection to servera closed.
      [student@workstation ~]$ ssh student@servera
      ...output omitted...
      [student@servera 14:45:05 ~]$ 
  2. Assign a value to a local shell variable. Variable names can contain uppercase or lowercase letters, digits, and the underscore character. Retrieve the variable value.

    1. Create a new variable called file with a value of tmp.zdkei083. The tmp.zdkei083 file exists in the student home directory.

      [student@servera 14:47:05 ~]$ file=tmp.zdkei083
    2. Retrieve the value of the file variable.

      [student@servera 14:48:35 ~]$ echo $file
      tmp.zdkei083 
    3. Use the variable name file and the ls -l command to list the tmp.zdkei083 file. Use the rm command and the file variable name to delete the tmp.zdkei083 file. Confirm it has been deleted.

      [student@servera 14:59:07 ~]$ ls -l $file
      -rw-rw-r--. 1 student student 0 Jan 23 14:59 tmp.zdkei083
      [student@servera 14:59:10 ~]$ rm $file
      [student@servera 14:59:15 ~]$ ls -l $file
      ls: cannot access 'tmp.zdkei083': No such file or directory 
  3. Assign a value to the editor variable. Use one command to make the variable an environment variable.

    [student@servera 14:46:40 ~]$ export EDITOR=vim
    [student@servera 14:46:55 ~]$ echo $EDITOR
    vim 
  4. Exit from servera.

    [student@servera 14:47:11 ~]$ exit
    logout
    Connection to servera closed.
    [student@workstation ~]$ 

Finish

On workstation, run the lab edit-shell finish script to complete this exercise.

[student@workstation ~]$ lab edit-shell finish

This concludes the guided exercise.

Revision: rh124-8.2-df5a585