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
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.
On workstation, use the ssh command to log in to servera.
[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$
Use Vim to edit the ~/.bashrc configuration file.
[student@servera ~]$vim ~/.bashrc
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
Exit from servera and log in again using the ssh command to update the command prompt.
[student@servera ~]$exitlogout Connection to servera closed.[student@workstation ~]$ssh student@servera...output omitted... [student@servera 14:45:05 ~]$
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.
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
Retrieve the value of the file variable.
[student@servera 14:48:35 ~]$echo $filetmp.zdkei083
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 $filels: cannot access 'tmp.zdkei083': No such file or directory
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 $EDITORvim
Exit from servera.
[student@servera 14:47:11 ~]$exitlogout Connection to servera closed. [student@workstation ~]$
This concludes the guided exercise.