[IFT 201]
Computer and Network Systems: Organization and Administration
LAB Assignment 1
Score: 60 pts (Part I: 10 pts; Part II: 50 pts)
Part I
Objectives:
1. To create a Linux Virtual Machine (VM), which will be used in Part II of this lab as well as some future labs in the course.
1. If you are already using Ubuntu or any other Linux flavor (https://en.wikipedia.org/wiki/List_of_Linux_distributions), you may directly start with Part II of this lab. If you are using Windows or Mac:
a. You may use either Oracle VirtualBox (https://www.virtualbox.org/) or VMware (which can be downloaded from http://onthehub.com/download/software-discounts/vmware for ASU students) for your VM setup.
b. Download and Ubuntu Desktop (https://www.ubuntu.com/download) ISO file for your VM.
Some useful links for setting up a Virtual Machine:
https://linus.nci.nih.gov/bdge/installUbuntu.html
https://help.ubuntu.com/community/VMware
Deliverables for Part I:
1. Power up your Ubuntu Virtual Machine. Open the terminal (https://askubuntu.com/a/183777). Enter the command “ls” (list directory contents. Take a screenshot of your output.
2. Write a one paragraph essay on what you learned and turn in the essay along with the file list screenshot (above) in one single Word/pdf document.
Part II
Deliverables for Part II:
· Create four (4) different files, one for each section (I – IV).
· Name them lab1.1, lab1.2, lab1.3, and lab1.4
· Zip them all and submit.
· Note that the first file (lab1.1) can be created using any text editor. But all the other files are the capture of your work in the section using the command script lab1.x (“x” is to be replaced with the appropriate section number: 2, 3, or 4)
I. Learning about the history UNIX operating system
The following questions are about UNIX operating system. Webpages at the following URLs will be of great help.
http://www.computinghistorymuseum.org/teaching/papers/research/
http://www.bell-labs.com/history/unix/
http://www.levenez.com/unix/
http://www.unix-systems.org/what_is_unix/history_timeline.html
a. When did the first version of UNIX come out and what was its name?
b. Who were the authors of UNIX?
c. Where (organization) was UNIX designed and written?
d. When (year) was UNIX rewritten in C?
e. When did BSD UNIX come out?
f. When did FreeBSD come out?
Use the Ubuntu Virtual Machine created in Part I for the rest of the lab.
II. Understanding the Linux File System
These activities are designed for use with Mark Sobell’s A Practical Guide to Linux Commands, Editors, and Shell Programming, Third Edition. All page numbers designated as Sobell (e.g., Sobell, page 123) refer to this book. These assignments use the same conventions as the Sobell book. Before getting started, read “Conventions Used in This Book” (Sobell, pages 24–26) to become familiar with the conventions used in this activity.
These activities assume you have access to a system running Linux. Linux can be running natively or on a virtual machine. You must be able to interact with a bash (Bourne Again Shell) command line, either on a console or on a virtual terminal. See Sobell, page 26, for information on logging in from a terminal and Sobell, page 28, for information on working from the command line.
Objectives and Outcomes
In this activity you will learn the concepts of home directory, working directory, absolute pathname, and relative pathname. You will learn to use cd to make another directory the working directory, pwd to display the name of the working directory, rm to delete a ordinary file, and mkdir/rmdir to create and remove directory files. You will also learn to use touch create an empty file, ls –l to display file ownership and permissions and chmod to change file permissions.
Use the script utility (Sobell, page 62) to capture your work as you go through the steps of this lab. You will end up with a file that shows the work you have done. You will submit this file to your instructor as deliverable of the activity.
The syntax for the script command is: script filename (example script lab1.2)
Activity
1. Your home directory is the directory you are working in when you first log in on the system. Up to this point you have worked only in your home directory. When called by itself, the cd (change directory; Sobell, page 92) command makes your home directory the working directory (the directory you are working in). The pwd (print working directory; Sobell, page 86) command displays the name of the working directory. Give a cd command to make sure you are working in your home directory. Then give a pwd command to confirm you are working in your home directory. What is the name of your home directory?
$ cd
$ pwd
/home/ift201-ubuntu
2. The mkdir (make directory; Sobell, page 90) utility creates a directory. Use mkdir to create a directory named two as a subdirectory of your home directory. Use file to make sure two exists and is a directory.
$ mkdir two
$ file two
two: directory
3. An absolute pathname (Sobell, page 88) starts with a slash and traces a path from the root directory to the file identified by the pathname. As step 1 shows, the pwd command displays the absolute pathname of the working directory. When you call cd with an argument of the name of a directory, it makes that directory the working directory. Use cd to make two the working directory and then give a pwd command to confirm the name of the working directory.
$ cd two
$ pwd
/home/ift201-ubuntu /two
4. Use vim or vi to create a file named fox in the two directory (vi fox; then type “i” to start typing text. Type in whatever you wish; then press ESC, then :x to exit back to the prompt). Use ls to list the name of fox.
$ ls fox
fox
or
$ ls
fox
5. When you give ls an argument that is the name of a directory, ls displays the contents of that directory. Give an ls command with an argument of the absolute pathname of two (see step 3) to display the contents of the two directory. When you use an absolute pathname, it does not matter which directory is your working directory.
$ ls /home/ift201-ubuntu /two
fox
6. Make your home directory the working directory. A relative pathname (Sobell, page 89) is a pathname that does not start with a slash, it starts from (is relative to) the working directory. Give an ls command with an argument of two (a relative pathname) to display the contents of the two directory.
$ cd
$ ls two
fox
7. The rmdir utility removes an empty directory. Show that rmdir cannot remove the two directory while it holds a file.
$ rmdir two
rmdir: failed to remove 'two': Directory not empty
Remove fox from the two directory using a relative pathname and then remove the (empty) two directory.
$ rm two/fox
$ rmdir two
8. You can use the touch utility (Sobell, pages 94 and 985) to create an empty file quickly. Use touch to create a file named dog in the working directory. Use ls to confirm the file was created.
$ touch dog
$ ls dog
dog
9. Use ls –l (Sobell, page 98) to display the permissions of the file you just created. Who owns the file? To which group does it belong? Which permissions does the owner of the file have? The group? Others?
$ ls -l dog
-rw-r--r-- 1 max max 0 2012-10-15 12:20 dog
Based on the output of ls shown above, the owner of the file has read and write permissions while the group and others have only read permission. Max owns the file and the file belongs to the max group. Your group and others permissions may be different.
10. Display the permissions of /bin/bash. Who owns the file? To which group does it belong? Which permissions does the owner of the file have? The group? Others? Which permissions apply to you?
$ ls -l /bin/bash
-rwxr-xr-x 1 root root 934336 2010-04-18 19:16 /bin/bash
Based on the output of ls shown above, the owner of the file has read, write, and execute permissions while the group and others have only read and execute permissions. The owner of the file is root and the file belongs to the root group. The permissions for others (read and execute) apply to you because you are not the user named root and you are not a member of the
group named root.
11. Only the owner of a file (or a user working with root privileges) can change the permissions of a file. Using numeric arguments to chmod (Sobell, page 100), change the permissions of the file you created in step 1 so the owner has read and write permissions and the group and others have no permissions. Next change the permissions so the owner, the group, and others have only read permissions. Display the permissions of the file before you start and after each change.
$ ls -l dog
-rw-r--r-- 1 max max 0 2012-10-15 12:20 dog
$ chmod 600 dog
$ ls -l dog
-rw------- 1 max max 0 2012-10-15 12:20 dog
$ chmod 444 dog
$ ls -l dog
-r--r--r-- 1 max max 0 2012-10-15 12:20 dog
Section II Deliverable Information
This activity gives you practice using the vim editor to create and modify files and introduces you to some fundamental commands (vim, cd, pwd, rm, mkdir, rmdir, ls –l, touch, and chmod) required to manipulate and view files within Linux. Using script to capture your work in this activity allows you to turn the resulting file in to your instructor.
III. Understanding the Shell and I/Os
These activities are designed for use with Mark Sobell’s A Practical Guide to Linux Commands, Editors, and Shell Programming, Third Edition. All page numbers designated as Sobell (e.g., Sobell, page 123) refer to this book. These assignments use the same conventions as the Sobell book. Before getting started, read “Conventions Used in This Book” (Sobell, pages 24–26) to become familiar with the conventions used in this activity.
These activities assume you have access to a system running Linux. Linux can be running natively or on a virtual machine. You must be able to interact with a bash (Bourne Again Shell) command line, either on a console or on a virtual terminal. See Sobell, page 26, for information on logging in from a terminal and Sobell, page 28, for information on working from the command line.
Objectives and Outcomes
In this activity you will learn about the terminology, structure, and processing of the command line including arguments, options, built-ins, corrections, and pathname expansion. You will use cat, echo, and ls to learn about standard input and standard output, including learning how to use cat to create a short file.
Use the script utility (Sobell, page 62) to capture your work as you go through the steps of this lab. You will end up with a file that shows the work you have done. You can submit this file to your instructor as part of the activity.
The syntax for the script command is: script filename (example script lab3.3)
Activity
1. On a command line, what is a token? What is an argument and how does it usually affect a command? What is an option and how does it usually affect a command? How can you usually distinguish an argument from an option?
A token is a series of nonblank characters on the command line.
An argument is a token that a command acts on.
An option is a token that modifies how the command works.
Options frequently begin with one or two hyphens; most arguments do not begin with a hyphen.
2. Review the previous labs. List one or more command lines in each of the following categories: a command line with zero arguments, one argument, two arguments, one option, and one option and one argument.
Zero arguments:
$ cd
$ hostname
$ ls
$ pwd
One argument:
$ cat days
$ cd two
$ echo $0
$ file two
$ help echo
$ less /etc/services
$ lpr pizza
$ ls fox
$ man man
$ mkdir two
$ rmdir two
$ rm pizza
$ sort days
$ touch dog
$ type days
$ vim pizza
Two arguments:
$ cp pizza pizza2
$ grep small pizza
$ ls pizza xxxx
$ mv pizza2 pizza
One option:
$ cat --help
One option and one argument:
$ ls -l dog
3. Most utilities have many options. You can read the man page or use the ––help option to learn which options a utility accepts. Experiment with the ls –r (reverse) option and try combining it with the –l option. Try using the cp –r (recursive) option to copy a directory hierarchy. Use the head –n (substitute a number for n ) option to display the first n lines of a file instead of the default 10; try the same option with tail. Many utilities accept the
––version option to display version and license information. Experiment with this option on some of the utilities you are familiar with.
4. What is a builtin (Sobell, page 153)? How does a builtin differ from a utility? The built-ins man page describes the bash builtins. Which builti-ns have you used so far?
A builtin is a utility that is built into the shell.
While a builtin is part of the shell, a utility stands alone in a separate file.
Some builtins you may have used are cd, pwd, and echo.
5. The echo builtin copies its arguments to the screen. Given the following command line and its output, how can you repeat the command line without retyping it (Sobell, page 31)?
$ echo hi there
hi there
Press the UP ARROW key and then RETURN to repeat the previous command. Alternatively,
you can give the command !!.
After giving the preceding command, how can you edit the command to replace hi with hello (Sobell, page 31)?
$ echo hi there
hi there
$ ^hi^hello^
hello there
6. Using pathname expansion (Sobell, page 148), list the files in the /usr/bin directory that have the characters ab anywhere in their names.
$ ls /usr/bin/*ab*
List the files in the /usr/bin directory that begin with the letter u. Next list those that begin with un.
$ ls /usr/bin/u*
$ ls /usr/bin/un*
List the files in /usr/bin that have names that are one character long.
$ ls /usr/bin/?
List the files in your home directory that begin with a period followed by the letters bash (.bash).
$ cd
$ ls .bash*
The initial cd command makes sure you are working in your home directory.
7. “The Keyboard and Screen as Standard Input and Standard Output” on page 135 of Sobell explains how to use the cat utility to read from standard input (defaults to the keyboard) and write to standard output (defaults to the screen). Use cat as shown in Figure 5-5 on page 135 of Sobell to copy standard input to standard output. Press CONTROL-D on a line by itself to terminate cat.
$ cat
My name is Max.
My name is Max.
Bye.
Bye.
CONTROL-D
$
8. The echo builtin copies its arguments to standard output which, by default, bash directs to the screen.
$ echo This message goes to standard output.
This message goes to standard output.
The cat utility sends the contents of a file specified by its argument to standard output.
$ cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
Redirect standard output (Sobell, page 136) of echo to write a short message to a file and then use cat to display the contents of the file.
$ echo hi there > hi.file
$ cat hi.file
hi there
9. As demonstrated in step 7, when you do not specify an argument for cat, cat copies standard input to standard output. Redirect standard input to cat to come from the file you created in the previous step. Do not redirect standard output from cat; it will appear on the screen.
$ cat < hi.file
hi there
10. Redirect the output of an ls –l command to a file named ls.out. Display ls.out using cat.
$ ls -l > ls.out
$ cat ls.out
...
or
$ ls -l > ls.out
$ cat < ls.out
...
11. The who utility (Sobell, page 70) lists the users who are logged in on the system. Append the output (Sobell, page 140) of the who utility to the ls.out file you created in the previous step. Display the augmented ls.out file using cat.
$ who >> ls.out
$ cat ls.out
...
What happens if you omit one of the greater-than signs (use > in place of >>)? Try it and see.
The original content of ls.out is overwritten by the output of who.
12. Redirect standard output of cat to create a file named days that holds the names of the days of the week in chronological order, one per line. Do not redirect standard input to cat; it will come from the keyboard. Remember to press CONTROL-D on a line by itself to exit from cat.
$ cat > days
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
CONTROL-D
$
Use cat to read the days file and send it to standard output, through a pipeline, to standard input of the sort (Sobell, pages 58 and 143) utility. The result will be a list of days in alphabetical order.
$ cat days | sort
Friday
Monday
Saturday
Sunday
Thursday
Tuesday
Wednesday
Replace sort in the preceding command with grep (Sobell, page 56) with an argument of (uppercase) T. The result will be a list of days that have an uppercase T in their names in chronological order.
$ cat days | grep T
Tuesday
Thursday
Next create a filter (Sobell, page 144) by repeating the preceding command but sending standard output of grep through a pipeline to standard input of sort. The result will be a list of days that have an uppercase T in their names in alphabetical order.
$ cat days | grep T | sort
Thursday
Tuesday
13. Produce a long listing of the /etc, /usr/bin, and /sbin directories, sending the output to a file and running the command in the background (Sobell, page 146).
$ ls -l /etc /usr/bin /sbin > ls.big &
[1] 17392
Section III Deliverable Information
This activity gives you practice using the vim editor to create and modify files and introduces you to some fundamental commands required to manipulate and view files within Linux. Using script to capture your work in this activity allows you to turn the resulting file in to your instructor.
IV. Generating Shell Scripts
These activities are designed for use with Mark Sobell’s A Practical Guide to Linux Commands, Editors, and Shell Programming, Third Edition. All page numbers designated as Sobell (e.g., Sobell, page 123) refer to this book. These assignments use the same conventions as the Sobell book. Before getting started, read “Conventions Used in This Book” (Sobell, pages 24–26) to become familiar with the conventions used in this activity.
These activities assume you have access to a system running Linux. Linux can be running natively or on a virtual machine. You must be able to interact with a bash (Bourne Again Shell) command line, either on a console or on a virtual terminal. See Sobell, page 26, for information on logging in from a terminal and Sobell, page 28, for information on working from the command line.
The syntax for the script command is: script filename (example script lab3.4)
Objectives and Outcomes
In this activity you will learn to write and execute a shell script that includes comments. You will use chmod to make the file that holds the script executable and include a line that starts with #! in the script to make sure bash executes it. This activity also provides an introduction to positional parameters. You will also learn to write more advanced shell scripts that work with command-line arguments, control structures, and temporary files. Using read, these scripts will read information the user enters and, using echo, display information based on what the user enters. You will also learn about processes, PIDs, and using export to modify the environment.
Use the script utility (Sobell, page 62) to capture your work as you go through the steps of this lab. You will end up with a file that shows the work you have done. You can submit this file to your instructor as part of the activity.
Activity
1. Use vim or cat (see previous activities) to create a file named short with the following line in it:
echo 'hi there'
2. Use cat to verify the contents of short and then try to execute it. Use ls –l to display the permissions for short. Read the tip on Sobell, page 286.
$ cat short
echo 'hi there'
$ ./short
-bash: ./short: Permission denied
$ ls -l short
-rw-r--r--. 1 max pubs 16 10-19 13:31 short
3. Use chmod (Sobell, pages 99 and 285) to make the file executable, display the permissions for short, and try executing the file again.
$ chmod u+x short
$ ls -l short
-rwxr--r--. 1 max pubs 16 10-19 13:31 short
or
$ chmod 755 short
$ ls -l short
-rwxr-xr-x. 1 max pubs 16 10-19 13:31 short
$ ./short
hi there
4. Add a line that starts with #! (Sobell, page 287) to the beginning of short to make sure it is executed by bash.
In vi/vim, you can add a line above the current position of the cursor by pressing O (upper case o) and type the line, then press ESC key when done
To save and exit vi/vim, press :x
$ cat short
#!/bin/bash
echo 'hi there'
5. Add a comment line (Sobell, page 288) to short that explains what the script does.
In vi/vim, you can add a line below the current position of the cursor by pressing o (lower case o) and type the line, then press ESC key when done
To save and exit vi/vim, press :x
$ cat short
#!/bin/bash
# This script sends the string 'hi there' to standard output
echo 'hi there'
6. Within a shell script, the shell expands $1 (a variable called a positional parameter; Sobell, page 462) to the first argument on the command line the script was called with. Write and execute a script named first that displays (sends to standard output) the first argument on the command line it was called with. Include the #! line and a comment. Remember to make the file
executable.
$ cat first
#!/bin/bash
#
# This script sends its first argument to standard output
#
echo $1
$ ./first Hello
Hello
7. Write a shell script that copies the file named by its first argument to a file with the same name with the filename extension of .bak. Thus, if you call the script with the argument first (and a file named first exists in the working directory), after the script runs you would have two files: first and first.bak. Demonstrate that the script works properly.
$ cat cptobak
#!/bin/bash
#
# This script copies the file named by its first argument
# to the same name with a filename extension of .bak.
#
cp $1 $1.bak
$ ls
cptobak first short
$ ./cptobak first
$ ls
cptobak first first.bak short
8. Read the caution titled “Always quote positional parameters” on page 462 of Sobell. Use touch to create a file whose name has a SPACE in it. What happens when you give that filename as an argument to cptobak from the previous step?
$ touch aa\ bb
$ ls -l aa*
-rw-rw-r-- 1 mark mark 0 Jan 15 16:35 aa bb
$ ./cptobak aa*
cp: target `bb.bak' is not a directory
The shell passes one argument (that includes a SPACE) to cptobak: aa bb. But when the shell that is running cptobak parses $1, it expands it to two arguments because it contains an unquoted SPACE; the shell passes to cp four arguments:
cp aa bb aa bb.bak
When you pass more than two arguments to cp, the last argument must be a directory: cp copies the files named by the first arguments into the directory named by the last argument. If the last argument is not a directory, cp displays an error message. For more information see the second format of cp on Sobell, page 754.
Modify the cptobak script from the previous step by quoting the positional parameters in the cp line. Now what happens when you use the script to make a copy of a file with a SPACE in its name?
$ cat cptobak
...
cp "$1" "$1.bak"
$ ./cptobak aa*
$ ls aa*
aa bb aa bb.bak
The shell expands $0 to the name of the calling program (Sobell, page 461), $1–$n to the individual command-line arguments (positional parameters; Sobell, page 462), $* (Sobell, page 465) to all positional parameters, and $# (Sobell, page 466) to the number of positional parameters.
9. Write a script named all that displays (sends to standard output) the name of the calling program, the number of positional parameters, and a list of positional parameters. Include the #! line (Sobell, page 287) and a comment (Sobell, page 288). Remember to make the file executable (Sobell, page 100). Test the script with 0, 1, and 5 positional parameters.
$ cat all
#!/bin/bash
#
# Program to display its name, the number of arguments it
# was called with, and a list of those arguments.
#
echo "This script was called as $0."
echo "This script was called with $# arguments."
echo "The arguments were: $*"
$ ./all
This script was called as ./all.
This script was called with 0 arguments.
The arguments were:
$ ./all one
This script was called as ./all.
This script was called with 1 arguments.
The arguments were: one
$ ./all 11 12 13 14 15
This script was called as ./all.
This script was called with 5 arguments.
The arguments were: 11 12 13 14 15
10. Make a symbolic link (Sobell, page 113) named linkto to the all script you wrote in the previous step. Call linkto with two arguments. What does the script report as the name it was called as?
$ ln -s all linkto
$ ./linkto one two
This script was called as ./linkto.
This script was called with 2 arguments.
The arguments were: one two
11. Write a script named myname that uses echo (most of the examples in Chapter 10 use this utility) to prompt the user with Enter your name: , reads into a variable the string the user types in response to the prompt, and then displays Hello followed by the string the user typed. When you run the program it should look like this:
$ ./myname
Enter your name: Max Wild
Hello Max Wild
$ cat myname
#!/bin/bash
#
# Program to prompt the user, read the string the user types, # and display the string the user typed
#
echo -n "Enter your name: "
read ustring
echo "Hello" $ustring
12. Rewrite myname from the previous step, calling it myname2. Have this version of the program prompt the user for a string, but instead of displaying Hello and the string on the screen (sending it to standard output) redirect the output so the program writes only the string the user entered (and not Hello) to the temporary file named PID.name where PID is the process ID
number (Sobell, page 467) of the process running the script. Display the contents of the PID.name file.
$ cat myname2
#!/bin/bash
#
# Program to prompt the user, read the string the user types, # and write the string the user enters to $$.name
#
echo -n "Enter your name: "
read ustring
echo $ustring > $$.name
$ ./myname2
Enter your name: Max Wild
$ ls
18218.name cptobak first.bak mine myname2
all first linkto myname short
$ cat 18218.name
Max Wild
13. Write and run a script named looper that uses the for (Sobell, page 434) control structure to loop through the command-line arguments and display each argument on a separate line.
$ cat looper
#!/bin/bash
#
# Program to display its arguments one per line
#
for idx
do
echo $idx
done
$ ./looper a b c d
a
b
c
d
14. Rewrite looper from the previous step, calling it looper2. Have this version of the program use the for...in control structure (Sobell, page 432) to perform the same task.
$ cat looper2
#!/bin/bash
#
# Program to display its arguments on one line
#
for idx in $*
do
echo $idx
done
15. Write a script named ifthen that prompts the user with >> and reads a string of text from the user. If the user enters a nonnull string, the script displays You entered: followed by the string; otherwise it displays Where is your input?. Use an if...then...else control structure (Sobell, page 424) to implement the two-way branch in the script. Use the test (Sobell, pages 420 and 978) built-in to determine if the user enters a null string. What do you have to do to avoid getting an error message when you prompt with >>? (There are several ways to construct the test statement.)
$ cat ifthen
#!/bin/bash
#
# Program to prompt the user and display the string the
# user entered. If the user enters nothing, query the user.
#
echo -n ">> "
read userinput
if [ "$userinput" == "" ]
then
echo "Where is your input?"
else
echo "You entered: " $userinput
fi
You must quote the >> characters to prevent the shell from interpreting these characters and generating an error message when you display this prompt.
16. Write and run a simple shell script named echomyvar that displays the PID (Sobell, page 467) of the process running the script and value of the variable named myvar. Display the PID of the interactive shell you are working with. What is the value of the variable within the process running the shell script? Are the interactive shell and the shell running the script run by the same or different processes (do they have the same PID)?
$ cat echomyvar
echo The PID of this process is $$
echo The value of myvar is: $myvar
$ echo $$
2651
$ ./echomyvar
The PID of this process is 4392
The value of myvar is:
The value of the myvar variable within the process running the shell script is null. The interactive shell and the script are run by different processes (that have different PIDs).
The example near the top of Sobell, page 473, demonstrates a way to put a variable in the environment of a script you are calling without declaring the variable in the interactive shell you are running. Use this technique to assign a value to myvar, place it in the environment of echomyvar, and run echomyvar. After running the script, is myvar set in the interactive shell?
$ myvar=sam ./echomyvar
The PID of this process is 4411
The value of myvar is: sam
$ echo $myvar
$
No, myvar is not set in the interactive shell.
On the command line, assign a value to the variable named myvar and then run echomyvar again. Which value does the script display?
$ myvar=zach
$ ./echomyvar
The PID of this process is 4428
The value of myvar is:
The script displays a null value.
Use the export (Sobell, page 472) builtin in the interactive shell to place myvar in the environment and run echomyvar. (You can export myvar without assigning a new value to it.) Did the script display the value of myvar this time? Is the PID of the interactive shell the same or different from the PID of the script?
$ export myvar
$ ./echomyvar
The PID of this process is 4452
The value of myvar is: zach
$ echo $$
2651
Yes, the script displayed the value of myvar; the PIDs are different.
Call export without an argument and send the output through grep to display the export attribute for myvar. The export builtin and declare –x perform the same function.
$ export | grep myvar
declare -x myvar="zach"
Use export –n (Sobell, page 473) to unexport myvar. Show that myvar is a
shell variable but is no longer in the environment.
$ export -n myvar
$ echo $myvar
zach
$ export | grep myvar
Use the unset (Sobell, page 304) built-in to remove myvar. Show that myvar is not available in the interactive shell or in the environment.
$ unset myvar
$ echo $myvar
$ export | grep myvar
Section IV Deliverables
This activity gives you practice using positional parameters, comments, temporary files, and control structures in shell scripts that query the user and read information the user enters. It also has you work with PIDs, the export builtin, and the environment. Using script to capture your work in this activity allows you to turn the resulting file in to your instructor.