Changes

Jump to: navigation, search

Tutorial12: Shell Scripting - Part 2

3,337 bytes added, 10:29, 4 August 2020
LINUX PRACTICE QUESTIONS
=INVESTIGATION 3: USING STARTUP FILES =
In this section, you will learn how to ..customize your Bash Linux shell by creating and testing a startup file.
'''Perform the Following Steps:'''
# xUse the '''more''' command to view the contents of the start-up file called '''/etc/profile''' (eg. <span style="color:blue;font-weight:bold;font-family:courier;">more /etc/profile</span>)<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''' (eg. <span style="color:blue;font-weight:bold;font-family:courier;">more /etc/bashrc</span>)<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 "'''.bashrc'''"<br><br># Let's move your .bashrc file to prevent accidental overwrite. Issue the following linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">mv ~/.bashrc ~.bashrc.bk</span><br><br>If you experience an error message "''No such file or directory''", just ignore since there is no startup file to backup.<br><br># Use a text editor like vi or nano to create the text file called '''~/.bashrc''' (eg. <span style="color:blue;font-weight:bold;font-family:courier;">vi ~/.bashrc</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;">[</span>" is the open square bracket symbol):<br><span style="font-family:courier;">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># Save your editing session and exit the text editor (eg. with vi: press '''ESC''', then type ''':wx''' 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;">. ~/.bashrc</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># 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 ~/.bashrc.bk ~/.bashrc</span><br><br>If you experience an error message "''No such file or directory''", just ignore.<br><br>
 # : After you complete the Review Questions sections to get additional practice, then work on your<br>online assignment 3.<br><br>
= LINUX PRACTICE QUESTIONS =
'''Review Questions:'''
# xWhat is the purpose of the '''/etc/profile''' startup file?<br><br># x What is the purpose of the '''/etc/bashrc''' startup file?<br><br># xWhat is the purpose of the '''~/.bashrc''' startup file?<br><br># xWhat is the purpose of the ~/.bash_logout file?<br><br># xWrite <u>code</u> for the '''~/.bashrc''' file below to clear the screen, welcome the user by their username, and display a list of all users currently logged into your Matrix server. Insert blank lines between each of those elements.<br><br># x# x# xWrite a command to <u>run</u> the recently created '''~/.bashrc''' startup file from the previous question without exiting and re-logging into your Matrix account.<br><br>
[[Category:ULI101]]
13,420
edits

Navigation menu