CSE 303, Winter 2007, Assignment 1

Due: Friday 12 February 2007, 6:00pm

 

Important: Please make sure to test your assignment solution on attu !!! If it works at home, it may not work in the lab. We will be testing all your assignment solutions on attu.

 

Updates

 

Assignment goal

You will get experience using the Linux bash shell, using emacs, and writing a short script.

 

Documentation

In addition to the lecture notes, you may find "The Linux Pocket Guide" a useful reference for completing this assignment

There is also a bash manual available on the web

Getting ready (this part is not graded)

Work through the "getting started guide" including changing your shell permanently to bash. If any of these instructions do not work for you, please contact a TA or talk to another student in the class.

Download the file: hw1.tar.gz.

If you are already logged in to attu, the easiest way to do this is to execute the following command:

> wget http://www.cs.washington.edu/education/courses/303/07wi/assignments/hw1.tar.gz

Extract all the files for this assignment using the following commands:

Step1: decompress the tar file. Note that question 3 below asks you to use Google to figure out the definition of a "tar file".
> gunzip hw1.tar.gz

Step2: extract the files from the tar file
> tar xvf hw1.tar

You should now see a directory called hw1.

If you see it, you are ready to start the assignment. If this procedure did not work for you, please contact a TA or talk to another student in the class.

 

1. Understanding simple commands

Execute the following commands and explain what each one does.

Write your answers in a file called "problem1.txt". Write only one or two sentences per command.

Note on auto-completion: when you type commands or file names, try to type the first few letters only and press the TAB key. The shell will try to automatically complete (finish typing) the file name or command for you.

 

Basic file and directory operations

File viewing and simple file manipulation

Shell variables and some useful shortcuts

Input/output redirection and combining commands

Before trying the commands below, make sure that your working directory is hw1 (you should be able to do this with the following command: "cd ~/hw1/").

 

2. Using manpages

The command man displays an online manual page or manpage for a given program.

Use the command man to see the documentation for wc. The documentation should include information about wc's options. Use wc with at least one possible option. In a file called "problem2.txt" write the exact command that you used (including all options and arguments). Give a one sentence explanation of wc and the option(s) that you used.

Note: another way to get information about the options of a program is to invoke the program with the option --help. For example: wc --help.

 

3. Using Google

Google is a great source of information that you must learn to use.

Using Google, find a short (one or two sentences) definition for a "tar file".

In a file called " problem3.txt", write the definition that you found along with the URL of the page where you found the information.

 

4 - Processes

Launch the program irun4ever. This C program executes an infinite loop that prints a message every second.

Open another window and examine the list of all processes that you are running:

> ps ux

Find the process id (pid) of irun4ever using one of the commands below:

> ps ux | grep irun4ever

> ps -C irun4ever

What is the process id of irun4ever?

Kill irun4ever using the command kill.

In a file called problem4.txt, write the process id of irun4ever and the exact command that you used to kill it.

 

5 - Aliases

Create an alias for the command rm such that executing rm prompts the user for a confirmation before actually removing the file. With your alias, typing:

> rm mouse.txt

Should trigger the following prompt:

> rm: remove regular file `mouse.txt`?

Hint: Try "man rm" or try using Google to find the appropriate option for the rm program.

Put your solution in a file called myalias. Running source myalias should successfully add your alias to the shell.

 

6 - Short script

We provided you a short bash script called hw1.sh, that takes one argument as input, prints it, and exits.

Try to execute hw1.sh. Make sure you have the execute permission on the file.

Based on hw1.sh, create a script called merge.sh. The script should take 3 arguments (let's call them f1, f2, and f3) and works as follows:

Example. Executing your script on the provided files, file1.txt and file2.txt, as follows:

> merge.sh dst.txt file1.txt file2.txt

should produce the following output:

> First line in "dst.txt" is a

> Last line in "dst.txt" is z

And the final content of dst.txt should be:

a
b
c
d
e
f
g
h
w
z

7 - Extra credit

Modify your .bashrc so that your command line prompt looks as follows:

servername:path_to_current_directory username$

For example, if your username is happyjoe and you are in directory ~/hw1/ on attu1, your prompt should look like:

attu1:~/hw1 happyjoe$

Note that when you log in to attu, you actually end-up on one of attu1, attu2, attu3, or attu4.

The .bashrc file should be directly in your home directory: under ~/.bashrc. If it does not exist, you need to create it. After modifying your .bashrc, to see the effect of your changes, you need to open a new subshell by typing bash on the command line or you can simply execute "source ~/.bashrc" (we will talk about the differences between invoking another bash and using source in class). Remember that if you open a new subshell by typing bash, you later can exit that subshell by typing exit.

As explained in the Linux Pocket Guide, page 33 ("Tailoring Shell Behavior"), the contents of the ~/.bashrc file are read and executed when you open a new shell. However, when you first log in, a different file, called ~/.bash_profile is read and executed. To make sure you see the effects of your changes even in your login shell, you can put the following .bash_profile file in your home directory. This file simply reads and executes the commands inside your .bashrc. The content of this file should become clear to you after the lecture on Monday, January 8th.

 

Turn-in instructions

You should work on this assignment in a group of two. Each group should turn-in only one copy of the solution. Please make sure to write both names inside each file that you hand in.

You should turn in the following files:

Please find the detailed turn-in instructions here.