IT 244: Introduction to Linux/Unix
Homework 9
Due
Sunday, November 10th at 11:59 PM
What You Need to Do
- Modify .bash_profile
in your home directory as described below
- Create the script hw9.sh
with Unix commands that will do what is described in the steps
below
- This file must be in an hw9
directory under your hw directory
Setup
- In your home directory run
touch .bash_profile
-
From your home directory go to your it244
directory
cd it244
- Go to your hw directory
cd hw
- Create an hw9 directory
mkdir hw9
- Enter this new directory
cd hw9
- Create hw9.sh
nano hw9.sh
Specification
.bash_profile
- Edit your .bash_profile in
your home directory using
nano
- You do not have to write Step comments in your
.bash_profile file.
-
Go to your home directory and edit .bash_profile
to define the global variable glenn
whose value is the absolute pathname of my home directory.
-
Again in .bash_profile define an alias
gh which will take you to my home directory
using the variable defined above.
-
Also in .bash_profile define a function
go_show, that will
- Go to the directory named in the first command
line argument
- Print your current location
- Print the contents of your current directory
The directory this function takes you to will be specified as an
argument to the function on the command line.
You will need to use a positional parameter to do this.
hw9.sh
- Create the file hw9.sh inside
your hw9 directory using
nano
- Write the Unix command to perform the action specified
by each step
- Be sure to write a Step comment before the Unix
commands for each step
-
Run the
source
command on your
~/.bash_profile startup file in your home
directory.
Print to the terminal the value of the variable
glenn.
-
Using a pipeline,
grep
and a command that will show all
your global variables, print to the screen the full definition of
the variable glenn.
Do not use echo
to do this.
The command to show all global variables was mentioned in the first
class were global variables were discussed.
-
Aliases and functions are not global, so they cannot normally be run
inside a shell script.
That is why I asked you to run source
on
~/.bash_profile.
Once you do that, the aliases and functions defined in you
.bash_profile will be available inside
your the process running your script.
Run a command that will show the definition of the function
go_show
-
Use the function go_show to move to my home directory using the global
variable glenn.
-
Run a command that will show all the aliases you have currently defined.
-
Run a command that will show the last 20 commands in your history list.
-
Create the variable glenn_home whose value
is the following
The home directory of my instructor is /home/ghoffman
When you define this variable, you must use the value of the
variable glenn.
Also, the value assigned to glenn_home
must be contaned in a single string and you must
use the value of glenn inside this string.
Now print the value of glenn_home to the
terminal.
Testing
Copyright © 2020 Glenn Hoffman. All rights reserved. May not be reproduced without permission.