Red Hat System Administration I
Use shell variables and variable expansion to run commands, and set an environment variable to adjust the default editor for new shells.
Outcomes
Edit a user profile.
Create a shell variable.
Create an environment variable.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that all required resources are available.
[student@workstation ~]$ lab start edit-bashconfig
Instructions
Change the
studentuser'sPS1shell variable to[\u@\h \t \w]$(remember to put the value ofPS1in quotation marks and to include a trailing space after the dollar sign). This change adds the time to the prompt.Use the
sshcommand to log in toserveraas thestudentuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$Use Vim to edit the
~/.bashrcconfiguration file.[student@servera ~]$
vim ~/.bashrcAdd the
PS1shell variable and its value to the~/.bashrcfile. Set the value of the shell variable, including a trailing space at the end, inside quotation marks....output omitted... export PATH
PS1='[\u@\h \t \w]$ 'Exit from
serveraand log in again by using thesshcommand to update the command prompt, or execute the~/.bashrcfile by using thesource ~/.bashrccommand.[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 variable called
filewith a value oftmp.zdkei083. Thetmp.zdkei083file exists in thestudenthome directory.[student@servera 14:47:05 ~]$
file=tmp.zdkei083Retrieve the value of the
filevariable.[student@servera 14:48:35 ~]$
echo $filetmp.zdkei083Use the
filevariable name and thels -lcommand to list thetmp.zdkei083file. Use thermcommand and thefilevariable name to delete thetmp.zdkei083file. Verify that the file is deleted.[student@servera 14:59:07 ~]$
ls -l $file-rw-r--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
EDITORvariable. Use one command to assign the variable as an environment variable.[student@servera 14:46:40 ~]$
export EDITOR=vim[student@servera 14:46:55 ~]$echo $EDITORvimReturn to the
workstationsystem as thestudentuser.[student@servera 14:47:11 ~]$
exitlogout Connection to servera closed. [student@workstation ~]$