IT 244: Introduction to Linux/Unix
Homework 8
Due
Sunday, November 3rd at 11:59 PM
What You Need to Do
- Create the script hw8.sh
with Unix commands that will do what is described in the steps
below
- This file must be in an hw8
directory under your hw directory
Setup
-
From your home directory go to your it244
directory
cd it244
- Go to your hw directory
cd hw
- Create an hw8 directory
mkdir hw8
- Enter this new directory
cd hw8
- Create hw8.sh
nano hw8.sh
Specification
- Create the file hw8.sh inside
your hw8 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
-
Perform the following actions
- Run
ls
on a file that does not exist
- Run
ls
on the same file, but redirect Standard Error to
/dev/null
- Run
ls
on the same file, but redirect Standard Error to
errors.txt
- Print errors.txt to the terminal
The commands above do not have to be on the same line.
-
Using 3 commands on the same command line
- Go to your home directory
- Run
ls
- Return to your hw8 directory
-
For this step you will write two command lines.
Copy bother10.sh from /home/ghoffman/course_files/it244_files
to your hw8 directory.
This will be your first command line.
Write a single command line that
- Runs bother10.sh sending
the output to /dev/null, but does
this in the background
- Runs bother10.sh sending
the output to /dev/null, but does this
in the background
- Runs bother10.sh
sending the output to /dev/null,
but does this in the background
- Runs
ps
, but in the foreground
All of the above will be your second command line.
-
Using
pushd
to go to new directories and popd
to return to previous directories,
do the following.
- Go to your home directory
- Show your position in the filesystem
- Go to my home directory
- Show your position in the filesystem
- Return to your home directory
- Show your position in the filesystem
- Return to your hw8 directory
- Show your position in the filesystem
-
Do the following
- Create the local variable
foo and assign it the value "FOO"
- Create the global variable
bar and assign it the value "BAR"
- Write a single command that will print
the values of foo and
bar
-
Do the following
- Copy print_foo_bar.sh from
/home/ghoffman/course_files/it244_files
to your hw8 directory
- Run print_foo_bar.sh
The value of foo will not print because it is local to the
login shell and cannot be seen in the subshell running
print_foo_bar.sh.
-
Do the following
- Create the global variable
my_city
and assign it the name of the town you live in
- Write an
echo
statement that uses
my_city
to tell me where you live.
If I were to run this command the outout would be
I live in Somerville
-
There is a keyword shell variable which the shell uses to find the
directory that contains the executable file to run a command.
Print the value of this varable.
-
Print the value of the keyword shell variable whose value is the
absolute pathname of your default shell.
-
Run a command that will show you all your global variables.
Testing
Copyright © 2020 Glenn Hoffman. All rights reserved. May not be reproduced without permission.