Open main menu

CDOT Wiki β

Changes

Tutorial 12 - Shell Scripting - Part 2

4,588 bytes added, 14:14, 14 November 2021
no edit summary
: In the next investigation, we will learn to create / modify '''startup files'''<br>to <u>customize</u> your Linux shell environment.
 
=INVESTIGATION 4: USING START-UP FILES =
In this investigation, you will learn how to '''customize''' your '''Bash Linux shell environment'''<br>by creating and testing a '''start-up''' file.
 
 
 
'''Perform the Following Steps:'''
 
# Issue a Linux command to change to your '''home''' directory.<br><br>
# Issue a Linux command to <u>confirm</u> you are located in the '''home''' directory.<br><br>
# Use the '''more''' command to view the contents of the '''default start-up''' file called '''/etc/profile''' <br><br>This file contains the '''default settings''' when you open your Bourne shell (eg. if issuing the command '''sh''').<br><br>
# Use the '''more''' command to view the contents of the start-up file called '''/etc/bashrc'''<br><br>This file contains the '''default settings''' when you '''open your Bash shell''' (eg. if issuing the command '''bash''').<br><br>Since we are using the '''Bash shell''' by default, let's create a '''customized Bash start-up file'''.<br>This startup file is located in your '''home''' directory using the name "'''.bash_profile'''"<br><br>Let's move your <span style="font-weight:bold;font-family:courier;">.bash_profile</span> file to prevent '''accidental overwrite'''.<br><br>
# Issue the following linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">mv ~/.bash_profile ~/.bash_profile.bk</span><br><br>If you experience an error message "''No such file or directory''",<br>just ignore this command since there is no '''~/.bash_profile''' file in your home directory.<br><br>
# Use a text editor like vi or nano to create the text file called '''~/.bash_profile''' (eg. <span style="color:blue;font-weight:bold;font-family:courier;">vi ~/.bash_profile</span>)<br><br>If you are using the nano text editor, refer to notes on text editing in a previous week in the course schedule.<br><br>
# Enter the following lines in your shell script (the symbol "<span style="font-family:courier;font-weight:bold;">[</span>" is the open square bracket symbol):<br><span style="font-family:courier;font-weight:bold;">clear<br>echo -e -n "\e[0;34m"<br>echo "Last Time Logged in (for security):"<br>echo<br>lastlog -u $USER<br>echo<br>echo -e -n "\e[m"</span><br><br>'''NOTE:''' You will notice there is '''NO she-bang line''' since this is a '''start-up''' file.<br><br>
# Save your editing session and exit the text editor (eg. with vi: press '''ESC''', then type ''':x''' followed by '''ENTER''').<br><br>
# You can test run the startup file without exiting and re-entering your Bash shell environment.<br>Issue the following:<br><span style="color:blue;font-weight:bold;font-family:courier;">. ~/.bash_profile</span><br><br>What do you notice?<br><br>
# '''Exit''' your current Bash shell session.<br><br>
# '''Login''' again to your matrix account.<br><br>Did you start-up file customize your Bash shell environment with colours?<br><br>'''NOTE:''' This is where you can make your Linux shell environment values '''persistent'''<br>(i.e. saved regardless of exit and login to your Bash Shell such as '''aliases''', '''umask''', etc.).<br><br>
# Issue the following linux command to '''restore''' your previous settings for your bashrc startup file:<br><span style="color:blue;font-weight:bold;font-family:courier;">mv ~/.bash_profile.bk ~/.bash_profile</span><br><br>If you experience an error message "''No such file or directory''", just ignore.<br><br>
# '''Exit''' your current Bash shell session.<br><br>
# '''Login''' again to your matrix account.<br><br>What did you notice this time?<br><br>
# After you complete the Review Questions sections to get additional practice.
 
= FURTHER STUDY =
I hope this series of tutorials have been helpful in teaching you basic Linux OS skills.
<br><br>
In order to get efficient in working in the Linux environment requires '''practice''' and '''applying'''<br>what you have learned to perform Linux operating system administration including:<br>'''user management''', '''installing and removing applications''', '''network services''' and '''network security'''.
<br><br>
Although you are '''NOT''' required to perform '''Linux administration''' for this course,<br>there are useful '''course notes''' and '''TUTORIALS''' for advanced Linux server administration<br>that have been created for the Networking / Computer Support Specialist stream:
 
 
:* OSL740: Administration of Open Source Systems
:* OSL840: Advanced Administration of Open Source Systems
 
 
Take care and good luck in your future endeavours &nbsp; <span style="font-family:courier;font-weight:bold;">:)</span>
= LINUX PRACTICE QUESTIONS =